private FoodDTO Create(FoodViewModel viewModel) { try { log.Debug(FoodViewModel.FormatFoodViewModel(viewModel)); FoodDTO food = new FoodDTO(); // copy values viewModel.UpdateDTO(food, null); //RequestContext.Principal.Identity.GetUserId()); // audit food.CreateBy = null; //RequestContext.Principal.Identity.GetUserId(); food.CreateOn = DateTime.UtcNow; // add log.Debug("_foodService.AddFood - " + FoodDTO.FormatFoodDTO(food)); int id = _foodService.AddFood(food); food.FoodId = id; log.Debug("result: 'success', id: " + id); return(food); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
private FoodDTO Update(FoodViewModel viewModel) { try { log.Debug(FoodViewModel.FormatFoodViewModel(viewModel)); // get log.Debug("_foodService.GetFood - foodId: " + viewModel.FoodId + " "); var existingFood = _foodService.GetFood(viewModel.FoodId); log.Debug("_foodService.GetFood - " + FoodDTO.FormatFoodDTO(existingFood)); if (existingFood != null) { // copy values viewModel.UpdateDTO(existingFood, null); //RequestContext.Principal.Identity.GetUserId()); // update log.Debug("_foodService.UpdateFood - " + FoodDTO.FormatFoodDTO(existingFood)); _foodService.UpdateFood(existingFood); log.Debug("result: 'success'"); } else { log.Error("existingFood: null, FoodId: " + viewModel.FoodId); } return(existingFood); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }