コード例 #1
0
        /// <summary>
        /// Get DeliveryReport by id
        /// </summary>
        /// <param name="id">DeliveryReport id</param>
        /// <returns>DeliveryReport json view model</returns>
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_deliveryReportService.GetDeliveryReport - deliveryReportId: " + id + " ");

                var deliveryReport = new DeliveryReportViewModel(_deliveryReportService.GetDeliveryReport(id));

                log.Debug("_deliveryReportService.GetDeliveryReport - " + DeliveryReportViewModel.FormatDeliveryReportViewModel(deliveryReport));

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

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

                throw;
            }
        }
コード例 #2
0
        private DeliveryReportDTO Create(DeliveryReportViewModel viewModel)
        {
            try
            {
                log.Debug(DeliveryReportViewModel.FormatDeliveryReportViewModel(viewModel));

                DeliveryReportDTO deliveryReport = new DeliveryReportDTO();

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

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

                // add
                log.Debug("_deliveryReportService.AddDeliveryReport - " + DeliveryReportDTO.FormatDeliveryReportDTO(deliveryReport));

                int id = _deliveryReportService.AddDeliveryReport(deliveryReport);

                deliveryReport.DeliveryReportId = id;

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

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

                throw;
            }
        }
コード例 #3
0
        private DeliveryReportDTO Update(DeliveryReportViewModel viewModel)
        {
            try
            {
                log.Debug(DeliveryReportViewModel.FormatDeliveryReportViewModel(viewModel));

                // get
                log.Debug("_deliveryReportService.GetDeliveryReport - deliveryReportId: " + viewModel.DeliveryReportId + " ");

                var existingDeliveryReport = _deliveryReportService.GetDeliveryReport(viewModel.DeliveryReportId);

                log.Debug("_deliveryReportService.GetDeliveryReport - " + DeliveryReportDTO.FormatDeliveryReportDTO(existingDeliveryReport));

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

                    // update
                    log.Debug("_deliveryReportService.UpdateDeliveryReport - " + DeliveryReportDTO.FormatDeliveryReportDTO(existingDeliveryReport));

                    _deliveryReportService.UpdateDeliveryReport(existingDeliveryReport);

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

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

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

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

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