Example #1
0
        /// <summary>
        /// Get DeliveryReportMessage by id
        /// </summary>
        /// <param name="id">DeliveryReportMessage id</param>
        /// <returns>DeliveryReportMessage json view model</returns>
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_deliveryReportMessageService.GetDeliveryReportMessage - deliveryReportMessageId: " + id + " ");

                var deliveryReportMessage = new DeliveryReportMessageViewModel(_deliveryReportMessageService.GetDeliveryReportMessage(id));

                log.Debug("_deliveryReportMessageService.GetDeliveryReportMessage - " + DeliveryReportMessageViewModel.FormatDeliveryReportMessageViewModel(deliveryReportMessage));

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

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

                throw;
            }
        }
Example #2
0
        private DeliveryReportMessageDTO Create(DeliveryReportMessageViewModel viewModel)
        {
            try
            {
                log.Debug(DeliveryReportMessageViewModel.FormatDeliveryReportMessageViewModel(viewModel));

                DeliveryReportMessageDTO deliveryReportMessage = new DeliveryReportMessageDTO();

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

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

                // add
                log.Debug("_deliveryReportMessageService.AddDeliveryReportMessage - " + DeliveryReportMessageDTO.FormatDeliveryReportMessageDTO(deliveryReportMessage));

                int id = _deliveryReportMessageService.AddDeliveryReportMessage(deliveryReportMessage);

                deliveryReportMessage.DeliveryReportMessageId = id;

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

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

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

            if (viewModel.DeliveryReportMessageId > 0)
            {
                var t = Update(viewModel);
                //return Json(true);
                //return JsonConvert.SerializeObject(t.DeliveryReportMessageId);
                return(Ok(t.DeliveryReportMessageId));
            }
            else
            {
                var t = Create(viewModel);
                //return Json(t.DeliveryReportMessageId);
                //return JsonConvert.SerializeObject(t.DeliveryReportMessageId);
                return(Ok(t.DeliveryReportMessageId));
            }
        }
Example #4
0
        private DeliveryReportMessageDTO Update(DeliveryReportMessageViewModel viewModel)
        {
            try
            {
                log.Debug(DeliveryReportMessageViewModel.FormatDeliveryReportMessageViewModel(viewModel));

                // get
                log.Debug("_deliveryReportMessageService.GetDeliveryReportMessage - deliveryReportMessageId: " + viewModel.DeliveryReportMessageId + " ");

                var existingDeliveryReportMessage = _deliveryReportMessageService.GetDeliveryReportMessage(viewModel.DeliveryReportMessageId);

                log.Debug("_deliveryReportMessageService.GetDeliveryReportMessage - " + DeliveryReportMessageDTO.FormatDeliveryReportMessageDTO(existingDeliveryReportMessage));

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

                    // update
                    log.Debug("_deliveryReportMessageService.UpdateDeliveryReportMessage - " + DeliveryReportMessageDTO.FormatDeliveryReportMessageDTO(existingDeliveryReportMessage));

                    _deliveryReportMessageService.UpdateDeliveryReportMessage(existingDeliveryReportMessage);

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

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

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

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

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