presentation & tools
This commit is contained in:
@ -6,9 +6,11 @@ using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Identity.EntityFramework;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Abstract.Identity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.ViewModels;
|
||||
using Yavsc.ViewModels.Administration;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
@ -83,9 +85,6 @@ namespace Yavsc.Controllers
|
||||
return new BadRequestObjectResult(ModelState);
|
||||
}
|
||||
|
||||
IdentityRole adminRole;
|
||||
adminRole = await _roleManager.FindByNameAsync(Constants.AdminGroupName);
|
||||
|
||||
var addToRoleResult = await _userManager.AddToRoleAsync(user, Constants.AdminGroupName);
|
||||
if (!addToRoleResult.Succeeded)
|
||||
{
|
||||
@ -146,6 +145,32 @@ namespace Yavsc.Controllers
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
[Authorize("AdministratorOnly")]
|
||||
public IActionResult GiveAdmin()
|
||||
{
|
||||
ViewBag.NewAdminId = new SelectList(context.Users, "Id", "UserName");
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize("AdministratorOnly")]
|
||||
[HttpPost()]
|
||||
public async Task<IActionResult> GiveAdmin(NewAdminViewModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var newAdmin = await context.Users.FirstOrDefaultAsync(u=>u.Id==model.NewAdminId);
|
||||
if (newAdmin==null) return HttpNotFound();
|
||||
var addToRoleResult = await _userManager.AddToRoleAsync(newAdmin, Constants.AdminGroupName);
|
||||
if (!addToRoleResult.Succeeded)
|
||||
{
|
||||
return View("Index");
|
||||
}
|
||||
AddErrors(addToRoleResult);
|
||||
}
|
||||
ViewBag.NewAdminId = new SelectList(context.Users, "Id", "UserName");
|
||||
return View();
|
||||
}
|
||||
private void AddErrors(IdentityResult result)
|
||||
{
|
||||
foreach (var error in result.Errors)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
@ -6,6 +7,7 @@ using Yavsc.Models.Relationship;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Authorize("AdministratorOnly")]
|
||||
public class HyperLinkController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
@ -22,14 +24,14 @@ namespace Yavsc.Controllers
|
||||
}
|
||||
|
||||
// GET: HyperLink/Details/5
|
||||
public async Task<IActionResult> Details(string id)
|
||||
public async Task<IActionResult> Details(string href, string method)
|
||||
{
|
||||
if (id == null)
|
||||
if (href == null || method ==null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == id);
|
||||
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == href && m.Method == method);
|
||||
if (hyperLink == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
@ -59,14 +61,14 @@ namespace Yavsc.Controllers
|
||||
}
|
||||
|
||||
// GET: HyperLink/Edit/5
|
||||
public async Task<IActionResult> Edit(string id)
|
||||
public async Task<IActionResult> Edit(string href, string method)
|
||||
{
|
||||
if (id == null)
|
||||
if (href == null || method ==null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == id);
|
||||
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == href && m.Method == method);
|
||||
if (hyperLink == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
@ -90,14 +92,15 @@ namespace Yavsc.Controllers
|
||||
|
||||
// GET: HyperLink/Delete/5
|
||||
[ActionName("Delete")]
|
||||
public async Task<IActionResult> Delete(string id)
|
||||
public async Task<IActionResult> Delete(string href, string method)
|
||||
{
|
||||
if (id == null)
|
||||
if (href == null || method ==null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == id);
|
||||
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == href && m.Method == method);
|
||||
|
||||
if (hyperLink == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
@ -109,9 +112,15 @@ namespace Yavsc.Controllers
|
||||
// POST: HyperLink/Delete/5
|
||||
[HttpPost, ActionName("Delete")]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> DeleteConfirmed(string id)
|
||||
public async Task<IActionResult> DeleteConfirmed(string HRef, string Method)
|
||||
{
|
||||
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == id);
|
||||
if (HRef == null || Method ==null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == HRef && m.Method == Method);
|
||||
|
||||
_context.HyperLink.Remove(hyperLink);
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction("Index");
|
||||
|
Reference in New Issue
Block a user