Exemplo n.º 1
0
        public DeleteFoodItemResponse DeleteFoodItem(DeleteFoodItemRequest request)
        {
            var response = new DeleteFoodItemResponse
            {
                IsSuccessful = false,
                Message      = ""
            };

            try
            {
                // Query and get the record where the ID matches via LINQ Where clause.
                var itemToDelete = _context.Foods
                                   .Where(x => x.Id == request.Id)
                                   .FirstOrDefault();

                if (itemToDelete != null)
                {
                    // Remove by tracking the record, and call SaveChanges() to physically delete the record.
                    _context.Remove(itemToDelete);
                    _context.SaveChanges();

                    response.IsSuccessful = true;
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.ToString();
            }

            return(response);
        }
Exemplo n.º 2
0
        public DeleteFoodItemResponse DeleteFoodItem(DeleteFoodItemRequest request)
        {
            var resp = new DeleteFoodItemResponse();

            var command = new DeleteFoodItemCommand(request.FoodItemId);

            resp = _repository.ExecuteCommand(command) as DeleteFoodItemResponse;

            return resp;
        }