Esempio n. 1
0
        public ActionResult UpdateFood([FromBody] FoodParameter foodParameter)
        {
            var userId = int.Parse(User.Claims.FirstOrDefault(x => x.Type == WsConstants.UserIdClaim)?.Value ?? "-1");
            var food   = _foodService.UpdateFood(foodParameter, userId);

            if (food != null)
            {
                return(Ok(food));
            }

            return(StatusCode(500));
        }
Esempio n. 2
0
        public FoodDto AddFood(FoodParameter foodParameter, int userId)
        {
            var newFood = new Food()
            {
                FoodName  = foodParameter.FoodName,
                Remark    = foodParameter.Remark,
                CreatedBy = userId,
                CreatedAt = DateTime.Now
            };

            _foodRepositories.AddFood(newFood);
            return(FoodDto.ToFoodDto(newFood));
        }
Esempio n. 3
0
        public FoodDto UpdateFood(FoodParameter foodParameter, int userId)
        {
            var food = _foodRepositories.GetFood(foodParameter.Id);

            if (food != null)
            {
                food.FoodName  = foodParameter.FoodName;
                food.Remark    = foodParameter.Remark;
                food.UpdatedBy = userId;
                food.UpdatedAt = DateTime.Now;
                return(FoodDto.ToFoodDto(_foodRepositories.UpdateFood(food)));
            }

            return(null);
        }