public async Task <CocktailResponse> UpdateAsync(int id, Domain.Models.Cocktail cocktail) { var existingCocktail = await _cocktailRepository.FindIdAsync(id); if (existingCocktail == null) { return(new CocktailResponse("Cocktail not found")); } existingCocktail.Name = cocktail.Name; existingCocktail.Thumb = cocktail.Thumb; existingCocktail.Instructions = cocktail.Instructions; try { _cocktailRepository.Update(existingCocktail); await _unitOfWork.CompleteAsync(); return(new CocktailResponse(existingCocktail)); } catch (Exception ex) { return(new CocktailResponse($"An error ocurred when updating the cocktail: {ex.Message}")); } }
public async Task <CocktailResponse> AddAsync(Domain.Models.Cocktail cocktail, List <Ingredient> ingredients) { try { await _cocktailRepository.AddAsync(cocktail, ingredients); await _unitOfWork.CompleteAsync(); return(new CocktailResponse(cocktail)); } catch (Exception ex) { return(new CocktailResponse($"An error occurred when saving the cocktail: {ex.Message}")); } }
public async Task AddAsync(Domain.Models.Cocktail cocktail, List <Ingredient> ingredients) { var result = await _context.Cocktails.AddAsync(cocktail); foreach (Ingredient ing in ingredients) { var ingRelation = new CocktailIngredient { CocktailId = result.Entity.Id, IngredientId = ing.Id }; await _context.Set <CocktailIngredient>().AddAsync(ingRelation); } }
public void Delete(Domain.Models.Cocktail cocktail) { _context.Cocktails.Remove(cocktail); }
public void Update(Domain.Models.Cocktail cocktail) { _context.Cocktails.Update(cocktail); }