public async Task <Category> AddAsync(CreateCategory command) { var category = new Category(command.Name); await _context.Categories.AddAsync(category); await _context.SaveChangesAsync(); return(category); }
public async Task <Rate> CreateAsync(CreateRate command, Recipe recipe) { var rate = new Rate(command.Value, command.Description); await _context.Rates.AddAsync(rate); recipe.Rates.Add(rate); await _context.SaveChangesAsync(); return(rate); }
public async Task <UserImage> AddAsync(CreateImage command, User user) { var image = new UserImage(command.ImageContent); await _context.UserImages.AddAsync(image); user.UserImage = image; await _context.SaveChangesAsync(); return(image); }
public async Task <Recipe> AddAsync(CreateRecipe command, User user) { var recipe = new Recipe(command.Name, command.Description, command.IsLactoseFree, command.IsGlutenFree, command.IsVegan, command.IsVegetarian); var components = CreateComponentsFromCommand(command.Components); await _context.Components.AddRangeAsync(components); recipe.Components = components; await _context.Recipes.AddAsync(recipe); user.Recipes.Add(recipe); await _context.SaveChangesAsync(); return(recipe); }
public async Task <(Admin Admin, string Login)> AddAsync(CreateAdmin command) { var login = RandomStringGenerator.GenerateUnique(); var loginHash = _hashManager.CalculateDataHash(_hashManager.CalculateDataHash(login).ToString()); if (await _context.Admins.ExistsInDatabaseAsync(command.Nick, loginHash) == true) { throw new CorruptedOperationException("Admin already exists."); } _hashManager.CalculatePasswordHash(command.Password, out var passwordHash, out var salt); var restoreKey = PasswordGenerator.GenerateRandomPassword(); var admin = new Admin(command.Nick, loginHash, salt, passwordHash, restoreKey); await _context.Admins.AddAsync(admin); await _context.SaveChangesAsync(); return(admin, login); }
public async Task <User> AddAsync(CreateUser command) { var loginHash = _hashManager.CalculateDataHash(command.Login); var emailHash = _hashManager.CalculateDataHash(command.Email); if (await _context.Users.ExistsInDatabaseAsync(command.Nick, loginHash, emailHash) == true) { throw new CorruptedOperationException("User already exists."); } _hashManager.CalculatePasswordHash(command.Password, out var passwordHash, out var salt); var restoreKey = PasswordGenerator.GenerateRandomPassword(); var user = new User(command.Nick, loginHash, salt, passwordHash, restoreKey, emailHash); await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }