コード例 #1
0
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_vehicleTypeService.GetVehicleType - vehicleTypeId: " + id + " ");

                var vehicleType = new VehicleTypeViewModel(_vehicleTypeService.GetVehicleType(id));

                log.Debug("_vehicleTypeService.GetVehicleType - " + VehicleTypeViewModel.FormatVehicleTypeViewModel(vehicleType));

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

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

                throw;
            }
        }
コード例 #2
0
        private VehicleTypeDTO Create(VehicleTypeViewModel viewModel)
        {
            try
            {
                log.Debug(VehicleTypeViewModel.FormatVehicleTypeViewModel(viewModel));

                VehicleTypeDTO vehicleType = new VehicleTypeDTO();

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

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

                // add
                log.Debug("_vehicleTypeService.AddVehicleType - " + VehicleTypeDTO.FormatVehicleTypeDTO(vehicleType));

                int id = _vehicleTypeService.AddVehicleType(vehicleType);

                vehicleType.VehicleTypeId = id;

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

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

                throw;
            }
        }
コード例 #3
0
        private VehicleTypeDTO Update(VehicleTypeViewModel viewModel)
        {
            try
            {
                log.Debug(VehicleTypeViewModel.FormatVehicleTypeViewModel(viewModel));

                // get
                log.Debug("_vehicleTypeService.GetVehicleType - vehicleTypeId: " + viewModel.VehicleTypeId + " ");

                var existingVehicleType = _vehicleTypeService.GetVehicleType(viewModel.VehicleTypeId);

                log.Debug("_vehicleTypeService.GetVehicleType - " + VehicleTypeDTO.FormatVehicleTypeDTO(existingVehicleType));

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

                    // update
                    log.Debug("_vehicleTypeService.UpdateVehicleType - " + VehicleTypeDTO.FormatVehicleTypeDTO(existingVehicleType));

                    _vehicleTypeService.UpdateVehicleType(existingVehicleType);

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

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

                throw;
            }
        }
コード例 #4
0
        //[ValidateAntiForgeryToken]
        public IHttpActionResult SaveList(VehicleTypeViewModel[] viewModels, int?id)
        {
            try
            {
                log.Debug("SaveList");

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

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