private static bool ValidateRole(DtoRole entity, out string errMsg) { errMsg = ""; if (entity == null) { errMsg = "用户数据为空,很检查后重试"; return(false); } if (string.IsNullOrEmpty(entity.RoleCode)) { errMsg += "权限标识不能为空;"; } if (string.IsNullOrEmpty(entity.RoleName)) { errMsg += "权限姓名不能为空;"; } if (string.IsNullOrEmpty(entity.AppCode)) { errMsg += "系统标识不能为空;"; } return(string.IsNullOrEmpty(errMsg)); }
public async Task <IActionResult> Edit(string id, string appcode, string pcode, string pname) { IRoleInfo model; if (string.IsNullOrEmpty(id)) { if (string.IsNullOrEmpty(appcode)) { throw new ArgumentNullException("appcode", "请先选择系统"); } model = new DtoRole { AppCode = appcode, ParentCode = pcode, ParentName = pname }; } else { model = await _service.GetRole(id); } if (string.IsNullOrEmpty(model.ParentCode)) { model.ParentName = "根角色"; } return(View(model)); }
public Role(DtoRole i, int UserId) { this.Id = i.Id; this.RoleType = i.Role; this.User_id = UserId; this.Store_id = i.Store?.Id; }
public bool CreateUser(string name, string email, string password) { DtoUser user = new DtoUser { Login = name, Email = email, Password = Crypto.HashPassword(password) }; DtoRole userRole = roleService.GetRoleByTitle("user"); if (!ReferenceEquals(userRole, null)) { user.Roles.Add(userRole); } userService.CreateUser(user); DtoUser createdUser = userService.GetUserByPredicate(usr => usr.Email.Equals(email, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (!ReferenceEquals(createdUser, null)) { folderService.CreateRootFolder(createdUser.ID); } return(true); }
public DtoRole CreateRole(DtoRole e) { var role = roleRepository.Create(e.ToDalRole()); uow.Commit(); return(role.ToDtoRole()); }
public async Task <ActionResult> Add(DtoRole dtoRole) { var role = new Role { Description = dtoRole.Description, Name = dtoRole.Name }; await _repoRole.CreateAsync(role); return(CreatedAtRoute("GetRoleByID", new { role.Id }, role)); }
/// <summary> /// Convert Bll Role entity to Dal entity /// </summary> /// <param name="role">bll entity</param> /// <returns>dal entity</returns> public static DalRole ToDalRole(this DtoRole role) { if (ReferenceEquals(role, null)) { return(null); } return(new DalRole { ID = role.ID, Role = role.Role }); }
public async Task <ActionResult> Update(DtoRole dtoRole, int id) { var roleToUpdate = await _repoRole.GetByIdAsync(id); if (roleToUpdate == null) { return(NotFound("No data in database")); } roleToUpdate.Name = dtoRole.Name; roleToUpdate.Description = dtoRole.Description; await _repoRole.UpdateAsync(roleToUpdate); return(NoContent()); }
/// <summary> /// Создать роль. /// </summary> /// <param name="newRole"> DTO с данными для создания роли. </param> /// <returns> Возвращает монаду созданной роли. </returns> public Either <Error, DtoRole> CreateRoles(DtoNewRole newRole) { var result = Role.Create(newRole).Bind( role => { _appContext.Roles.Add(role); return(_appContext.TrySaveChanges().Bind <Role>(_ => role)); }).Bind( role => { var createdRole = new DtoRole(role.Id, role.Name); return(Right <Error, DtoRole>(createdRole)); }); return(result); }
public async Task <ActionResult> CreateRole([FromBody] DtoRole model) { var checkRoleExist = await _roleManager.RoleExistsAsync(model.RoleName); if (checkRoleExist == false) { var roleToAdd = new IdentityRole(model.RoleName); var roleRes = await _roleManager.CreateAsync(roleToAdd); if (roleRes.Succeeded) { // return BadRequest("Role is not created"); return(Ok($"Uspesno kreirana rola")); } return(BadRequest("Neuspesno kreirana rola!")); } return(Conflict("Rola vec postoji!")); }
public override bool IsUserInRole(string email, string roleName) { DtoRole userRole = roleService.GetRoleByTitle(roleName); DtoUser user = userService.GetUserByPredicate(usr => usr.Email.Equals(email, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (ReferenceEquals(user, null)) { return(false); } if (!ReferenceEquals(userRole, null) && user.Roles.Contains(userRole, new RoleCompare())) { return(true); } return(false); }
public async Task <IActionResult> Save(int type, DtoRole entity) { JsonMsg msg = new JsonMsg(); try { string errMsg; bool valid = ValidateRole(entity, out errMsg); if (!valid) { msg.status = -1; msg.message = errMsg; return(Json(msg)); } entity.LastModifyTime = DateTime.Now; entity.LastModifyUserId = base.UserId; entity.LastModifyUserName = base.UserId; int ret = await this._service.SaveRole(entity, type); if (ret > 0) { msg.status = 0; } else { msg.status = -1; msg.message = "操作不成功,请稍后重试"; } } catch (Exception ex) { msg.status = -1; msg.message = "操作不成功:" + ex.Message; } return(Json(msg)); }
public void UpdateRole(DtoRole e) { roleRepository.Update(e.ToDalRole()); uow.Commit(); }
public void DeleteRole(DtoRole e) { roleRepository.Delete(e.ToDalRole()); uow.Commit(); }
public Role(DtoRole i, int UserId) { this.Id = i.Id; this.RoleName = i.Role; this.User_id = UserId; }