public async Task <Unit> Handle(RemoveRecipeRequest request, CancellationToken cancellationToken) { var recipe = await _context.GetRecipeForUpdate(request.RecipeKey, cancellationToken); recipe.SoftDelete(); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <ModelUpdateIdentifier> Handle(AddIngredientRequest request, CancellationToken cancellationToken) { var recipe = await _context.GetRecipeForUpdate(request.RecipeKey); if (recipe == null) { throw new RecordNotFoundException(nameof(Recipe), request.RecipeKey); } var existingIngredient = await _context.Ingredients .Where(x => x.Name == request.Name) .FirstOrDefaultAsync(cancellationToken); var ingredient = existingIngredient ?? _mapper.Map <Ingredient>(request); var recipeIngredient = recipe.AddIngredient(ingredient, request.UnitOfMeasure, request.Quantity); await _context.SaveChangesAsync(cancellationToken); return(new ModelUpdateIdentifier(recipeIngredient.Key, recipeIngredient.Version)); }