Browse Source

Added invitre code creation to main admin page.

core
Teknikode 4 years ago
parent
commit
0073e99c6d
  1. 22
      Teknik/Areas/Admin/Controllers/AdminController.cs
  2. 11
      Teknik/Areas/Admin/Views/Admin/Dashboard.cshtml
  3. 20
      Teknik/Scripts/Admin/Admin.js
  4. 7
      Teknik/bundleconfig.json

22
Teknik/Areas/Admin/Controllers/AdminController.cs

@ -158,19 +158,23 @@ namespace Teknik.Areas.Admin.Controllers @@ -158,19 +158,23 @@ namespace Teknik.Areas.Admin.Controllers
[ValidateAntiForgeryToken]
public IActionResult CreateInviteCode(string username)
{
if (UserHelper.UserExists(_dbContext, username))
InviteCode inviteCode = new InviteCode();
inviteCode.Active = true;
inviteCode.Code = Guid.NewGuid().ToString();
if (!string.IsNullOrEmpty(username))
{
if (!UserHelper.UserExists(_dbContext, username))
{
return new StatusCodeResult(StatusCodes.Status404NotFound);
}
User user = UserHelper.GetUser(_dbContext, username);
InviteCode inviteCode = new InviteCode();
inviteCode.Active = true;
inviteCode.Code = Guid.NewGuid().ToString();
inviteCode.Owner = user;
_dbContext.InviteCodes.Add(inviteCode);
_dbContext.SaveChanges();
return Json(new { result = new { code = inviteCode.Code } });
}
return new StatusCodeResult(StatusCodes.Status404NotFound);
_dbContext.InviteCodes.Add(inviteCode);
_dbContext.SaveChanges();
return Json(new { result = new { code = inviteCode.Code } });
}
[HttpPost]

11
Teknik/Areas/Admin/Views/Admin/Dashboard.cshtml

@ -1,5 +1,9 @@ @@ -1,5 +1,9 @@
@model Teknik.Areas.Admin.ViewModels.DashboardViewModel
<script>
var createInviteCode = '@Url.SubRouteUrl("admin", "Admin.Action", new { action = "CreateInviteCode" })';
</script>
<div class="container">
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
@ -11,4 +15,11 @@ @@ -11,4 +15,11 @@
<a href="@Url.SubRouteUrl("admin", "Admin.UploadSearch")">Upload Search</a>
</div>
</div>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<button type="button" class="btn btn-info" id="createInviteCode">Create Invite Code</button>
</div>
</div>
</div>
<bundle src="js/admin.min.js" append-version="true"></bundle>

20
Teknik/Scripts/Admin/Admin.js

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
$(function () {
$('#createInviteCode').click(function () {
$.ajax({
type: "POST",
url: createInviteCode,
data: AddAntiForgeryToken(),
success: function (html) {
if (html.result) {
$("#top_msg").css('display', 'none');
$("#top_msg").html('');
alert('Successfully created invite code for \'' + username + '\': ' + html.result.code);
}
else {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(html) + '</div>');
}
}
});
});
});

7
Teknik/bundleconfig.json

@ -1,4 +1,11 @@ @@ -1,4 +1,11 @@
[
{
"outputFileName": "./wwwroot/js/admin.min.js",
"inputFiles": [
"./wwwroot/lib/bootbox/js/bootbox.js",
"./wwwroot/js/app/Admin/Admin.js"
]
},
{
"outputFileName": "./wwwroot/js/uploadSearch.min.js",
"inputFiles": [

Loading…
Cancel
Save