示例#1
0
        private FoodTemplateDTO Create(FoodTemplateViewModel viewModel)
        {
            try
            {
                log.Debug(FoodTemplateViewModel.FormatFoodTemplateViewModel(viewModel));

                FoodTemplateDTO foodTemplate = new FoodTemplateDTO();

                // copy values
                viewModel.UpdateDTO(foodTemplate, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                foodTemplate.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                foodTemplate.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_foodTemplateService.AddFoodTemplate - " + FoodTemplateDTO.FormatFoodTemplateDTO(foodTemplate));

                int id = _foodTemplateService.AddFoodTemplate(foodTemplate);

                foodTemplate.FoodTemplateId = id;

                log.Debug("result: 'success', id: " + id);

                return(foodTemplate);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
示例#2
0
        private FoodTemplateDTO Update(FoodTemplateViewModel viewModel)
        {
            try
            {
                log.Debug(FoodTemplateViewModel.FormatFoodTemplateViewModel(viewModel));

                // get
                log.Debug("_foodTemplateService.GetFoodTemplate - foodTemplateId: " + viewModel.FoodTemplateId + " ");

                var existingFoodTemplate = _foodTemplateService.GetFoodTemplate(viewModel.FoodTemplateId);

                log.Debug("_foodTemplateService.GetFoodTemplate - " + FoodTemplateDTO.FormatFoodTemplateDTO(existingFoodTemplate));

                if (existingFoodTemplate != null)
                {
                    // copy values
                    viewModel.UpdateDTO(existingFoodTemplate, null); //RequestContext.Principal.Identity.GetUserId());

                    // update
                    log.Debug("_foodTemplateService.UpdateFoodTemplate - " + FoodTemplateDTO.FormatFoodTemplateDTO(existingFoodTemplate));

                    _foodTemplateService.UpdateFoodTemplate(existingFoodTemplate);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingFoodTemplate: null, FoodTemplateId: " + viewModel.FoodTemplateId);
                }

                return(existingFoodTemplate);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }