public async Task <JsonResult> Action(RoleActionModel model) { JsonResult json = new JsonResult(); IdentityResult result = null; // trying to edit a record if (!string.IsNullOrEmpty(model.ID)) { var role = await RoleManager.FindByIdAsync(model.ID); role.Name = model.Name; result = await RoleManager.UpdateAsync(role); } // trying to create a record else { var role = new IdentityRole(); role.Name = model.Name; result = await RoleManager.CreateAsync(role); } json.Data = new { Success = result.Succeeded, Message = string.Join(", ", result.Errors) }; return(json); }
public async Task <JsonResult> Action(RoleActionModel model) { JsonResult jsonResult = new JsonResult(); IdentityResult identityResult; if (!string.IsNullOrEmpty(model.ID)) { var Role = await RoleManager.FindByIdAsync(model.ID); Role.Id = model.ID; Role.Name = model.Name; identityResult = await RoleManager.UpdateAsync(Role); jsonResult.Data = new { Success = identityResult.Succeeded, Msg = string.Join(",", identityResult.Errors) }; return(jsonResult); } else { IdentityRole identityRole = new IdentityRole { Name = model.Name }; identityResult = await RoleManager.CreateAsync(identityRole); jsonResult.Data = new { Success = identityResult.Succeeded, Msg = string.Join(",", identityResult.Errors) }; return(jsonResult); } }
public async Task <JsonResult> Delete(RoleActionModel model) { JsonResult json = new JsonResult(); IdentityResult result = null; if (!string.IsNullOrEmpty(model.ID)) //we are trying to delete a record { var role = await RoleManager.FindByIdAsync(model.ID); result = await RoleManager.DeleteAsync(role); json.Data = new { Success = result.Succeeded, Message = string.Join(", ", result.Errors) }; } else { json.Data = new { Success = false, Message = "Invalid role." }; } return(json); }
public ActionResult Create() { var RoleAction = db.Role_Action; RoleModel roleModel = new RoleModel(); roleModel.RoleActions = new List <RoleActionModel>(); foreach (var a in RoleAction) { RoleActionModel ra = new RoleActionModel(); ra.CreateInd = a.Create_Ind; ra.ReadInd = a.Read_Ind; ra.UpdateInd = a.Update_Ind; ra.DeleteInd = a.Delete_Ind; ra.ActionId = a.Action_ID; ra.RoleId = a.Role_ID; ra.ActionName = a.Action.Action_Name; roleModel.RoleActions.Add(ra); } var distinctActions = roleModel.RoleActions.GroupBy(x => x.ActionId) .Select(g => g.FirstOrDefault()) .ToList(); roleModel.RoleActions = distinctActions; return(View(roleModel)); }
public async Task <ActionResult> Delete(RoleActionModel model) { var user = await RoleManager.FindByIdAsync(model.ID); await RoleManager.DeleteAsync(user); return(RedirectToAction("Index")); }
public async Task <ActionResult> Delete(string ID) { RoleActionModel model = new RoleActionModel(); var role = await RoleManager.FindByIdAsync(ID); model.ID = role.Id; return(PartialView("_Delete", model)); }
public async Task <ActionResult> UserRole(RoleActionModel model) { var role = new IdentityRole(); role.Name = model.Name; await RoleManager.CreateAsync(role); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit(RoleActionModel model) { var role = await RoleManager.FindByIdAsync(model.ID); role.Id = model.ID; role.Name = model.Name; await RoleManager.UpdateAsync(role); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit(string ID) { RoleActionModel model = new RoleActionModel(); if (!string.IsNullOrEmpty(ID)) { var role = await RoleManager.FindByIdAsync(ID); model.ID = role.Id; model.Name = role.Name; } return(PartialView("_Edit", model)); }
public async Task <ActionResult> Action(string ID) { RoleActionModel model = new RoleActionModel(); if (!string.IsNullOrEmpty(ID)) { var objectFirst = await RoleManager.FindByIdAsync(ID); model.ID = objectFirst.Id; model.Name = objectFirst.Name; } return(PartialView("_Action", model)); }
public async Task <ActionResult> Action(string ID) { RoleActionModel model = new RoleActionModel(); if (!string.IsNullOrEmpty(ID)) //we are trying to edit a record { var role = await RoleManager.FindByIdAsync(ID); model.ID = role.Id; model.Name = role.Name; } return(PartialView("_Action", model)); }
public async Task <ActionResult> Action(string ID) { RoleActionModel model = new RoleActionModel(); // AccomodationPackageActionModel model2 = new AccomodationPackageActionModel(); if (!string.IsNullOrEmpty(ID)) // we are trying to edit { var roles = await RoleManager.FindByIdAsync(ID); model.ID = roles.Id; model.Name = roles.Name; } // model. = model2.GetAllAccomodationPackages(); return(PartialView("_Action", model)); }
public async Task <ActionResult> Delete(string ID) { if (!string.IsNullOrEmpty(ID)) { var Role = await RoleManager.FindByIdAsync(ID); RoleActionModel model = new RoleActionModel { ID = Role.Id, Name = Role.Name }; return(PartialView("_Delete", model)); } else { return(PartialView("_Delete")); } }
public async Task <ActionResult> Delete(RoleActionModel model) { JsonResult jsonResult = new JsonResult(); IdentityResult identityResult; if (!string.IsNullOrEmpty(model.ID)) { var Role = await RoleManager.FindByIdAsync(model.ID); identityResult = await RoleManager.DeleteAsync(Role); jsonResult.Data = new { Success = identityResult.Succeeded, Message = string.Join(",", identityResult.Errors) }; } else { jsonResult.Data = new { Success = false, Message = "Empty Record " }; } return(jsonResult); }
public ActionResult Action() { RoleActionModel model = new RoleActionModel(); return(PartialView("_Action", model)); }
public ActionResult Create(RoleModel role) { var RoleAction = db.Role_Action; RoleModel roleModel = new RoleModel(); roleModel.RoleActions = new List <RoleActionModel>(); foreach (var a in RoleAction) { RoleActionModel ra = new RoleActionModel(); ra.CreateInd = a.Create_Ind; ra.ReadInd = a.Read_Ind; ra.UpdateInd = a.Update_Ind; ra.DeleteInd = a.Delete_Ind; ra.ActionId = a.Action_ID; ra.RoleId = a.Role_ID; ra.ActionName = a.Action.Action_Name; roleModel.RoleActions.Add(ra); } var distinctActions = roleModel.RoleActions.GroupBy(x => x.ActionId) .Select(g => g.FirstOrDefault()) .ToList(); roleModel.RoleActions = distinctActions; try { int Count = 0; bool create = true; bool read = true; bool update = true; bool delete = true; ViewBag.ErrorMsg = ""; var query = (from q in db.Roles where q.Role_Name.ToLower() == role.RoleName.ToLower() select q); if (query.Count() != 0) { ViewBag.ErrorMsg = "The role name exists, please provide a different role name"; return(View(roleModel)); } Role r = new Role(); r.Role_Name = role.RoleName; db.Roles.Add(r); foreach (var o in role.RoleActions) { Role_Action ra = new Role_Action(); ra.Action_ID = o.ActionId; ra.Role_ID = r.Role_ID; ra.Create_Ind = o.CreateInd; ra.Read_Ind = o.ReadInd; ra.Update_Ind = o.UpdateInd; ra.Delete_Ind = o.DeleteInd; db.Role_Action.Add(ra); create = ra.Create_Ind; if (create == false) { Count++; } read = ra.Read_Ind; if (read == false) { Count++; } update = ra.Update_Ind; if (update == false) { Count++; } delete = ra.Delete_Ind; if (delete == false) { Count++; } if (Count == (role.RoleActions.Count() * 4)) { ViewBag.Error = "Role must be assigned at least 1 action"; return(View(roleModel)); } } db.SaveChanges(); return(RedirectToAction("Index", "Role")); } catch { return(View(roleModel)); } }