public async Task <AddResult> AddUser(UserAddModel model) { if (model.AccountType == Roles.Owner) { throw new RestaurantBadRequestException("Csak egyetlen tulajdonos felhasználó létezhet!"); } if (model.AccountType != Roles.Chef && model.AccountType != Roles.Waiter) { throw new RestaurantBadRequestException("Hibás felhasználói szerepkör!"); } var existingUser = await UserManager.FindByNameAsync(model.UserName); if (existingUser != null) { throw new RestaurantBadRequestException("A megadott felhasználónév foglalt!"); } var user = new User { Email = model.Email, Name = model.Name, UserName = model.UserName, SecurityStamp = Guid.NewGuid().ToString(), IsActive = true }; var createResult = await UserManager.CreateAsync(user, model.Password); var addToResult = await UserManager.AddToRoleAsync(user, model.AccountType); if (!createResult.Succeeded || !addToResult.Succeeded) { throw new RestaurantInternalServerErrorException("Sikertelen felhasználó létrehozás!"); } return(new AddResult(user.Id)); }
public async Task <AddResult> AddUser(UserAddModel user) => await UserService.AddUser(user);