protected override async Task Handle(Command request, CancellationToken cancellationToken) { var foodProduct = await _repository.Get(request.Id); if (foodProduct is null) { throw new Exception("Waste product doesn't exist"); } await _repository.Delete(foodProduct); }
protected override async Task Handle(Command request, CancellationToken cancellationToken) { var foodProduct = await _repository.Get(request.Id); if (foodProduct is null) { throw new Exception("Waste product doesn't exist!"); } FoodCategory category = await _categoryRepository.GetByName(request?.Category?.Name); if (category is null) { category = new FoodCategory { Name = request?.Category?.Name }; await _categoryRepository.Add(category); } MapWasteProductViewToModel(foodProduct, request, category.Id); await _repository.Update(foodProduct); }