public async Task AddRoles(IEnumerable <AddRole> roles) { await RunTaskInTransaction(async() => { foreach (var model in roles) { var entity = new Data_Access_Layer.Role() { Name = model.Name }; await RoleRepository.Add(entity); await RoleClaimRepository .AddRange(model.Claims.Select(cl => new RoleClaim { Role = entity, ClaimType = cl.Type, ClaimValue = cl.Value })); } return(string.Empty); }); }
public async Task AddRole(AddRole model) { var transaction = _dbContext.Database.BeginTransaction(); try { var entity = new Data_Access_Layer.Role() { Name = model.Name, NormalizedName = model.Name.ToUpper() }; await RoleRepository.Add(entity); Save(); await RoleClaimRepository .AddRange(model.Claims.Select(cl => new RoleClaim { Role = entity, ClaimType = cl.Type, ClaimValue = cl.Value })); Save(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } }
public override Common.DTO.Role Map(Data_Access_Layer.Role entity) { var dto = base.Map(entity); Map(entity, dto); return(dto); }
public virtual Common.DTO.Role Map(Data_Access_Layer.Role entity) { return(new Common.DTO.Role { Id = entity.Id, Name = entity.Name, Claims = entity .RoleClaims .Select(Map) .ToList(), CreatedAt = entity.CreatedAt, LastModifiedAt = entity.LastModifiedAt }); }
public async Task <string> DeleteRole(Data_Access_Layer.Role role) { return(await RunTaskInTransaction(async() => { var users = UserRepository.GetByRole(role.Id); if (users.Any()) { return $"Użytkownicy są przypisani do roli {role.Name}"; } RoleRepository.Remove(role); return string.Empty; })); }
public void DeleteRole(Data_Access_Layer.Role role) { RoleRepository.Remove(role); Save(); }