public ActionResult AccountRoleAdd(AccountRoleModel model, GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAccountRoles)) return AccessDeniedView(); if (!ModelState.IsValid) { //display the first model error var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage); return Content(modelStateErrors.FirstOrDefault()); } if (ModelState.IsValid) { var entity = new AccountRole { Name = model.Name, SystemName = model.Name.ToSystemName(), Active = model.Active, IsSystemRole = false }; _accountService.InsertAccountRole(entity); } return List(command); }
public ActionResult AddRole(string teema, AccountRoleModel model) { if (ModelState.IsValid) { int myRoleId = entities.TeemaAccesses.Single(ta => ta.Teema.Name == teema && ta.User.Username == User.Identity.Name).RoleId; if (model.Role != TeemaRoles.Undefined) { if (myRoleId < (int)model.Role) { model.Role = (TeemaRoles)myRoleId; } if (!entities.TeemaAccesses.Any(ta => ta.Teema.Name == teema && ta.User.Username == model.Username)) { TeemaAccess ta = new TeemaAccess() { TeemaId = entities.Teemas.Single(t => t.Name == teema).Id, UserId = entities.Users.Single(u => u.Username == model.Username).Id, RoleId = (int)model.Role }; entities.TeemaAccesses.Add(ta); entities.SaveChanges(); } } model.Username = null; model.Role = TeemaRoles.Undefined; } return(PartialView(model)); }
public void Save(AuthContext context) { if (saveMask == SaveMask.None) { return; } var model = new AccountRoleModel { Id = Id, RoleId = (uint)Role.Role }; if ((saveMask & SaveMask.Create) != 0) { context.Add(model); } else { context.Remove(model); } saveMask = SaveMask.None; }
public ActionResult AccountRoleUpdate(AccountRoleModel model, GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAccountRoles)) return AccessDeniedView(); if (!ModelState.IsValid) { //display the first model error var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage); return Content(modelStateErrors.FirstOrDefault()); } var accountRole = _accountService.GetAccountRoleById(model.Id); if (accountRole == null) throw new ArgumentException("Không tìm thấy Vai trò nào", "id"); accountRole.Name = model.Name; accountRole.SystemName = model.Name.ToSystemName(); ; accountRole.Active = model.Active; _accountService.UpdateAccountRole(accountRole); return List(command); }
public IActionResult SaveAccountRole([FromBody] AccountRoleModel model) { var result = PermissionService.SavePermissionRole(model.AccountId, model.Roles, null); return(MyJson(result)); }
/// <summary> /// Create a new <see cref="AccountRole"/> from an existing database model. /// </summary> public AccountRole(AccountRoleModel model, RBACRole role) { Id = model.Id; Role = role; saveMask = SaveMask.None; }
public ActionResult List() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAccountRoles)) return AccessDeniedView(); var list = _accountService.GetAllAccountRoles(true); var gridModel = new GridModel<AccountRoleModel> { Data = list.Select(entity => { var m = new AccountRoleModel { Id = entity.Id, IsSystemRole = entity.IsSystemRole, Active = entity.Active, Name = entity.Name, SystemName = entity.SystemName }; return m; }), Total = list.Count }; return View(gridModel); }