Exemplo n.º 1
0
        public ActionResult <EditFood> EditFoodCategory(EditFood model)
        {
            try
            {
                IMapper mapper     = EDeliveryProfile.EditFood();
                var     editedFood = mapper.Map <Food>(model);

                var userIdClaim = User.FindFirst("MemberId")?.Value;
                var memberId    = int.TryParse(userIdClaim, out int id) ? id : 0;

                EDeliveryDBContext dBContext = new EDeliveryDBContext();
                var restaurantId             = dBContext.Restaurant.First(o => o.MemberId == memberId).RestaurantId;
                editedFood.RestaurantId = restaurantId;

                var categoryId = dBContext.Food.First(o => o.FoodId == model.FoodId).CategoryId;
                editedFood.CategoryId = categoryId;

                _repository.EditFood(editedFood);

                return(new ObjectResult(new { message = "success", statusCode = HttpStatusCode.OK, response = "Succesfuly edited food" }));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to edit the food:{ex}");
            }
            return(BadRequest("Failed to edit the food"));
        }