public IHttpActionResult UpdateAccess(UpdateRoleAccessModel model) { var role = db.Role.Where(r => r.Id == model.RoleId && r.Display).FirstOrDefault(); if (role == null) { return(NotFound()); } foreach (var access in model.Access) { var roleaccess = db.RoleAccess.Where(r => r.RoleId == model.RoleId && r.UserAccess == access.UserAccess).FirstOrDefault(); if (access.IsCheck) { if (roleaccess == null) { db.RoleAccess.Add(new RoleAccess { RoleId = model.RoleId, UserAccess = access.UserAccess }); } } else { if (roleaccess != null) { db.RoleAccess.Remove(roleaccess); } } } db.SaveChanges(); return(Ok(true)); }
public async Task <ActionResult> Access(UpdateRoleAccessModel model) { var response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, $"Administration/Role/UpdateAccess", model); if (response.isSuccess) { TempData["SuccessMessage"] = "Role access successfully updated."; await LogActivity(Modules.Setting, "Update Role Access", model); return(RedirectToAction("Access", new { id = model.RoleId })); } TempData["ErrorMessage"] = "Fail to update role access."; return(RedirectToAction("Access", new { id = model.RoleId })); }