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)); }
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)); }
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); }