예제 #1
0
        /// <summary>
        /// Get DeliveryReportMessageType by id
        /// </summary>
        /// <param name="id">DeliveryReportMessageType id</param>
        /// <returns>DeliveryReportMessageType json view model</returns>
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_deliveryReportMessageTypeService.GetDeliveryReportMessageType - deliveryReportMessageTypeId: " + id + " ");

                var deliveryReportMessageType = new DeliveryReportMessageTypeViewModel(_deliveryReportMessageTypeService.GetDeliveryReportMessageType(id));

                log.Debug("_deliveryReportMessageTypeService.GetDeliveryReportMessageType - " + DeliveryReportMessageTypeViewModel.FormatDeliveryReportMessageTypeViewModel(deliveryReportMessageType));

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

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

                throw;
            }
        }
예제 #2
0
        private DeliveryReportMessageTypeDTO Create(DeliveryReportMessageTypeViewModel viewModel)
        {
            try
            {
                log.Debug(DeliveryReportMessageTypeViewModel.FormatDeliveryReportMessageTypeViewModel(viewModel));

                DeliveryReportMessageTypeDTO deliveryReportMessageType = new DeliveryReportMessageTypeDTO();

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

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

                // add
                log.Debug("_deliveryReportMessageTypeService.AddDeliveryReportMessageType - " + DeliveryReportMessageTypeDTO.FormatDeliveryReportMessageTypeDTO(deliveryReportMessageType));

                int id = _deliveryReportMessageTypeService.AddDeliveryReportMessageType(deliveryReportMessageType);

                deliveryReportMessageType.DeliveryReportMessageTypeId = id;

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

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

                throw;
            }
        }
예제 #3
0
        //[ValidateAntiForgeryToken]
        /// <summary>
        /// Updates data for an existing DeliveryReportMessageType, or creates a new DeliveryReportMessageType if the Id is 0
        /// </summary>
        /// <param name="viewModel">DeliveryReportMessageType data</param>
        /// <returns>DeliveryReportMessageType id</returns>
        public IHttpActionResult Upsert(DeliveryReportMessageTypeViewModel viewModel)
        {
            log.Debug("Upsert");

            if (viewModel.DeliveryReportMessageTypeId > 0)
            {
                var t = Update(viewModel);
                //return Json(true);
                //return JsonConvert.SerializeObject(t.DeliveryReportMessageTypeId);
                return(Ok(t.DeliveryReportMessageTypeId));
            }
            else
            {
                var t = Create(viewModel);
                //return Json(t.DeliveryReportMessageTypeId);
                //return JsonConvert.SerializeObject(t.DeliveryReportMessageTypeId);
                return(Ok(t.DeliveryReportMessageTypeId));
            }
        }
예제 #4
0
        private DeliveryReportMessageTypeDTO Update(DeliveryReportMessageTypeViewModel viewModel)
        {
            try
            {
                log.Debug(DeliveryReportMessageTypeViewModel.FormatDeliveryReportMessageTypeViewModel(viewModel));

                // get
                log.Debug("_deliveryReportMessageTypeService.GetDeliveryReportMessageType - deliveryReportMessageTypeId: " + viewModel.DeliveryReportMessageTypeId + " ");

                var existingDeliveryReportMessageType = _deliveryReportMessageTypeService.GetDeliveryReportMessageType(viewModel.DeliveryReportMessageTypeId);

                log.Debug("_deliveryReportMessageTypeService.GetDeliveryReportMessageType - " + DeliveryReportMessageTypeDTO.FormatDeliveryReportMessageTypeDTO(existingDeliveryReportMessageType));

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

                    // update
                    log.Debug("_deliveryReportMessageTypeService.UpdateDeliveryReportMessageType - " + DeliveryReportMessageTypeDTO.FormatDeliveryReportMessageTypeDTO(existingDeliveryReportMessageType));

                    _deliveryReportMessageTypeService.UpdateDeliveryReportMessageType(existingDeliveryReportMessageType);

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

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

                throw;
            }
        }
예제 #5
0
        //[ValidateAntiForgeryToken]
        /// <summary>
        /// Save a list of DeliveryReportMessageType
        /// </summary>
        /// <param name="viewModels">DeliveryReportMessageType view models</param>
        /// <param name="id">(not used)</param>
        /// <returns>true if the operation is successfull</returns>
        public IHttpActionResult SaveList(DeliveryReportMessageTypeViewModel[] viewModels, int?id)
        {
            try
            {
                log.Debug("SaveList");

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

                        if (viewModel.DeliveryReportMessageTypeId > 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;
            }
        }