Ejemplo n.º 1
0
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_foodTemplateService.GetFoodTemplate - foodTemplateId: " + id + " ");

                var foodTemplate = new FoodTemplateViewModel(_foodTemplateService.GetFoodTemplate(id));

                log.Debug("_foodTemplateService.GetFoodTemplate - " + FoodTemplateViewModel.FormatFoodTemplateViewModel(foodTemplate));

                log.Debug("result: 'success'");

                //return Json(foodTemplate, JsonRequestBehavior.AllowGet);
                //return Content(JsonConvert.SerializeObject(foodTemplate), "application/json");
                //return foodTemplate;
                //return JsonConvert.SerializeObject(foodTemplate);
                return(Ok(foodTemplate));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
0
        //[ValidateAntiForgeryToken]
        public IHttpActionResult SaveList(FoodTemplateViewModel[] viewModels, int?id)
        {
            try
            {
                log.Debug("SaveList");

                if (viewModels != null)
                {
                    // save list
                    foreach (FoodTemplateViewModel viewModel in viewModels)
                    {
                        log.Debug(FoodTemplateViewModel.FormatFoodTemplateViewModel(viewModel));

                        if (viewModel.FoodTemplateId > 0)
                        {
                            var t = Update(viewModel);
                        }
                        else
                        {
                            var t = Create(viewModel);
                        }
                    }
                }
                else
                {
                    log.Error("viewModels: null");
                }

                //return Json(true);
                //return JsonConvert.SerializeObject(true);
                return(Ok(true));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }