public async Task <Recipe> Add(Recipe recipe) { var newRecipe = new Recipe { Image = recipe.Image, Servings = recipe.Servings, Time = recipe.Time, Title = recipe.Title, Description = recipe.Description, FkUser = recipe.FkUser }; await _dataContext.AddAsync(newRecipe); await _dataContext.SaveChangesAsync(); foreach (var item in recipe.Products) { var product = new Product { Name = item.Name, Quantity = item.Quantity, FkRecipe = newRecipe.Id }; await _dataContext.Product.AddAsync(product); } await _dataContext.SaveChangesAsync(); return(newRecipe); }
public async Task <Comment> Add(Comment comment) { await _dataContext.AddAsync(comment); await _dataContext.SaveChangesAsync(); return(comment); }
public async Task <Event> Add(Event ev) { await _dataContext.AddAsync(ev); await _dataContext.SaveChangesAsync(); return(ev); }
public async Task <bool> Delete(int id) { var value = await _dataContext.User.Where(x => x.Id == id).FirstOrDefaultAsync(); if (value == null) { return(false); } var values = _dataContext.User.Remove(value); await _dataContext.SaveChangesAsync(); return(true); }
public async Task <bool> Update(int id, NewProductDto[] newProducts) { var findProducts = await _dataContext.Product.Where(x => x.FkRecipe.Equals(id)).ToListAsync(); if (findProducts.Count == 0 || findProducts == null) { throw new ArgumentNullException(); } foreach (var item in findProducts) { var findProduct = await _dataContext.Product.FirstOrDefaultAsync(x => x.Id.Equals(item.Id)); foreach (var a in newProducts) { findProduct.Name = a.Name; findProduct.Quantity = a.Quantity; } _dataContext.Update(findProduct); } await _dataContext.SaveChangesAsync(); return(true); }
public async Task <User> Register(User user, string password) { CreatePasswordHash(password, out var passwordHash, out var passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; user.Token = CreateToken(user); await _context.User.AddAsync(user); await _context.SaveChangesAsync(); return(user); }