public IActionResult ChangeRights(int selectedRoleId, List <int> selectedRights) { base.CheckForLogin(); if (!base.CheckForRight(6)) { return(RedirectToAction("Index", "Home")); } RoleRepository repoRole = new RoleRepository(new RoleSQLContext()); RightRepository repoRight = new RightRepository(new RightSQLContext()); UserRepository repoUser = new UserRepository(new UserSQLContext()); if (selectedRoleId != 1) { repoRole.UpdateRightsOfRole(selectedRoleId, selectedRights); } else { ErrorRights(); } ConfirmUpdateRights(); return(RedirectToAction("ChangeRoleAndRights")); }
public void Setup() { controller = new DiffController(); leftRepository = new LeftRepository(); rightRepository = new RightRepository(); diffService = new DiffService(); }
private void ValiddatePermission(ActionExecutingContext filterContext, Account account, string areaName, string controller, string action, string filePath) { action = string.IsNullOrEmpty(Action) ? action : Action; var result = false; if (account != null) { if (!string.IsNullOrEmpty(areaName)) { // controller : area/controller controller = $"{areaName}/{controller}"; } // 用户所有的权限 IList <Permission> permission = null; // TODO : 取存在缓存里的数据 permission = filterContext.HttpContext.Session[filePath + account.User_Id] as IList <Permission>; if (permission == null) { RightRepository rightRepository = new RightRepository(); permission = rightRepository.GetPermission(account.User_Id, controller); // TODO : 放入缓存 filterContext.HttpContext.Session[filePath + account.User_Id] = permission; } //查询当前Action 是否有操作权限,大于0表示有,否则没有 int count = permission.Where(a => a.KeyCode.Equals(action, StringComparison.CurrentCultureIgnoreCase)).Count(); result = count > 0; if (!result) { if (filterContext.HttpContext.Request.IsAjaxRequest()) { filterContext.Result = new JsonResult() { Data = new { code = 1, msg = "你没有操作权限,请联系管理员!" } }; return; } filterContext.HttpContext.Response.StatusCode = 403; filterContext.Result = new ContentResult() { Content = "你没有操作权限,请联系管理员!" }; return; } else { return; } } else { filterContext.Result = new RedirectResult("/account/signin"); return; } }
public IActionResult ChangeRole(RoleViewModel RoleviewModel) { base.CheckForLogin(); if (!base.CheckForRight(5)) { return(RedirectToAction("Index", "Home")); } RoleRepository repoRole = new RoleRepository(new RoleSQLContext()); RightRepository repoRight = new RightRepository(new RightSQLContext()); UserRepository repoUser = new UserRepository(new UserSQLContext()); if (base.CheckForRight(5)) { RoleviewModel.HasRight = true; } RoleviewModel.Roles = repoRole.GetRoles(); RoleviewModel.Users = repoUser.GetUserList(); int selectedUserId = RoleviewModel.SelectedUserId; int selectedRoleId = RoleviewModel.SelectedRoleId; RoleviewModel.SelectedUser = RoleviewModel.Users.Find(x => x.Id == selectedUserId); RoleviewModel.SelectedRole = RoleviewModel.Roles.Find(x => x.Id == selectedRoleId); //Don't change the application's default admin if (RoleviewModel.SelectedUser.Id != 5) { UserRepository userRepository = new UserRepository(new UserSQLContext()); userRepository.UpdateUserRole(RoleviewModel.SelectedUser, RoleviewModel.SelectedRole); //Confirmation message apply / create other methods in other controllers (Tim) ConfirmChange(RoleviewModel); } else { ErrorRole(); } ChangeRightsViewModel RightsviewModel = new ChangeRightsViewModel(); if (base.CheckForRight(6)) { RightsviewModel.HasRight = true; } RightsviewModel.Roles = repoRole.GetRoles(); RightsviewModel.Rights = repoRight.GetRights(); RightsviewModel.SelectedRole = RightsviewModel.Roles.Find(f => f.Id != 1); return(View("ChangeRoleAndRights", Tuple.Create(RoleviewModel, RightsviewModel))); }
public IActionResult ChangeSelectedRole(int selectedRoleId) { base.CheckForLogin(); if (!base.CheckForRight(6)) { return(RedirectToAction("Index", "Home")); } RoleRepository repoRole = new RoleRepository(new RoleSQLContext()); RightRepository repoRight = new RightRepository(new RightSQLContext()); UserRepository repoUser = new UserRepository(new UserSQLContext()); RoleViewModel RoleviewModel = new RoleViewModel(); if (base.CheckForRight(5)) { RoleviewModel.HasRight = true; } RoleviewModel.Roles = repoRole.GetRoles(); RoleviewModel.Users = repoUser.GetUserList(); RoleviewModel.SelectedUser = RoleviewModel.Users.Find(u => u.Id == Convert.ToInt32(HttpContext.Session.GetInt32("id"))); RoleviewModel.SelectedRole = RoleviewModel.SelectedUser.Role; List <Role> roleList = repoRole.GetRoles(); ChangeRightsViewModel RightsviewModel = new ChangeRightsViewModel(); if (base.CheckForRight(6)) { RightsviewModel.HasRight = true; } RightsviewModel.Roles = roleList; RightsviewModel.Rights = repoRight.GetRights(); //Linq query var result = from role in roleList where role.Id == selectedRoleId select role; //Iterate through Linq query result foreach (var role in result) { RightsviewModel.SelectedRole = role; } return(View("ChangeRoleAndRights", Tuple.Create(RoleviewModel, RightsviewModel))); }
public IActionResult ChangeRoleAndRights() { base.CheckForLogin(); if (!base.CheckForRight(5) && !base.CheckForRight(6)) { return(RedirectToAction("Index", "Home")); } RoleRepository repoRole = new RoleRepository(new RoleSQLContext()); RightRepository repoRight = new RightRepository(new RightSQLContext()); UserRepository repoUser = new UserRepository(new UserSQLContext()); RoleViewModel RoleviewModel = new RoleViewModel(); if (base.CheckForRight(5)) { RoleviewModel.HasRight = true; } RoleviewModel.Roles = repoRole.GetRoles(); RoleviewModel.Users = repoUser.GetUserList(); RoleviewModel.SelectedUser = HttpContext.Session.GetInt32("id") == 5 ? RoleviewModel.Users.Find(u => u.Id != 5) : RoleviewModel.Users.Find(u => u.Id == Convert.ToInt32(HttpContext.Session.GetInt32("id"))); RoleviewModel.SelectedRole = RoleviewModel.SelectedUser.Role; ChangeRightsViewModel RightsviewModel = new ChangeRightsViewModel(); if (base.CheckForRight(6)) { RightsviewModel.HasRight = true; } RightsviewModel.Roles = repoRole.GetRoles(); RightsviewModel.Rights = repoRight.GetRights(); RightsviewModel.SelectedRole = RightsviewModel.Roles.Find(f => f.Id != 1); return(View("ChangeRoleAndRights", Tuple.Create(RoleviewModel, RightsviewModel))); }
public RightLogic() { _repository = new RightRepository(StorageTypeSetting.Setting); }
public JsonResponse Compare(int id) { JsonResponse response = new JsonResponse(); LeftRepository leftRepository = new LeftRepository(); RightRepository rightRepository = new RightRepository(); Base64Data leftData = leftRepository.GetById(id); Base64Data rightData = rightRepository.GetById(id); if (leftData != null) { response.Left = leftData.Base64Value; } if (rightData != null) { response.Right = rightData.Base64Value; } response.Id = id; //Validate if right or left data is present if (leftData == null && rightData == null) { response.Result = "Id " + id + " does not exists in Left and Right side"; } else if (leftData == null) { response.Result = "Id " + id + " does not exists in Left side"; } else if (rightData == null) { response.Result = "Id " + id + " does not exists in Right side"; } //Validate if right and left data are of equal size else if (!leftData.Base64Value.Length.Equals(rightData.Base64Value.Length)) { response.Result = "Not of Equal Size"; } else if (leftData.Base64Value.Equals(rightData.Base64Value)) { response.Result = "Equals"; } else { //Check the actual differences between the strings string diffMessage = string.Empty; bool diffFound = false; for (int i = 0; i < leftData.Base64Value.Length; i++) { if (!leftData.Base64Value[i].Equals(rightData.Base64Value[i]) && diffFound == false) { diffMessage = "Difference in position " + i; diffFound = true; if (i == leftData.Base64Value.Length - 1) { diffFound = false; response.Differences.Add(diffMessage); } } else if (leftData.Base64Value[i].Equals(rightData.Base64Value[i]) && diffFound) { diffMessage = diffMessage + " to " + (i - 1); diffFound = false; response.Differences.Add(diffMessage); } } response.Result = "Number of differences found: " + response.Differences.Count + "."; } return(response); }