public async Task <OperationDetails> Create(DutRole role) { var result = await _roleManager.CreateAsync(role); return(result.Succeeded ? new OperationDetails(true, "Додан новий тип користувача", "") : new OperationDetails(false, result.Errors.Aggregate("", (current, resultError) => current + (resultError + ",")), "Role")); }
public async Task <OperationDetails> Edit(DutRole model) { var role = await _roleManager.FindByIdAsync(model.Id); if (role != null) { IdentityResult result = await _roleManager.UpdateAsync(model); return(result.Succeeded ? new OperationDetails(true, "Оновлення пройшло успішно", "") : new OperationDetails(false, result.Errors.Aggregate("", (s, s1) => s + (s1 + ",")), "Role")); } return(new OperationDetails(false, "Тип користувача не знайден", "")); }
// Инициализация БД (начальная) public async Task SetInitialData(DutUser adminDto, List <string> roles) { foreach (var roleName in roles) { var role = await RoleManager.FindByNameAsync(roleName); if (role != null) { continue; } role = new DutRole() { Name = roleName }; await RoleManager.CreateAsync(role); } }