Example #1
0
        private PlannedRouteDTO Update(PlannedRouteViewModel viewModel)
        {
            try
            {
                log.Debug(PlannedRouteViewModel.FormatPlannedRouteViewModel(viewModel));

                // get
                log.Debug("_plannedRouteService.GetPlannedRoute - plannedRouteId: " + viewModel.PlannedRouteId + " ");

                var existingPlannedRoute = _plannedRouteService.GetPlannedRoute(viewModel.PlannedRouteId);

                log.Debug("_plannedRouteService.GetPlannedRoute - " + PlannedRouteDTO.FormatPlannedRouteDTO(existingPlannedRoute));

                if (existingPlannedRoute != null)
                {
                    // copy values
                    existingPlannedRoute.Name              = viewModel.Name;
                    existingPlannedRoute.RouteTypeId       = viewModel.RouteTypeId;
                    existingPlannedRoute.TransportTypeId   = viewModel.TransportTypeId;
                    existingPlannedRoute.Description       = viewModel.Description;
                    existingPlannedRoute.StartHour         = viewModel.StartHour;
                    existingPlannedRoute.EstimatedDuration = viewModel.EstimatedDuration;
                    existingPlannedRoute.TotalDistance     = viewModel.TotalDistance;
                    existingPlannedRoute.RouteDayOfTheWeek = viewModel.RouteDayOfTheWeek;
                    existingPlannedRoute.Active            = viewModel.Active;
                    existingPlannedRoute.IsDeleted         = viewModel.IsDeleted;

                    // audit
                    //existingPlannedRoute.UpdateBy = UserInfo.UserID;
                    existingPlannedRoute.UpdateOn = DateTime.UtcNow;

                    // update
                    log.Debug("_plannedRouteService.UpdatePlannedRoute - " + PlannedRouteDTO.FormatPlannedRouteDTO(existingPlannedRoute));

                    _plannedRouteService.UpdatePlannedRoute(existingPlannedRoute);

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

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

                throw;
            }
        }
Example #2
0
        private PlannedRouteDTO Create(PlannedRouteViewModel viewModel)
        {
            try
            {
                log.Debug(PlannedRouteViewModel.FormatPlannedRouteViewModel(viewModel));

                PlannedRouteDTO plannedRoute = new PlannedRouteDTO();

                // copy values
                plannedRoute.PlannedRouteId    = viewModel.PlannedRouteId;
                plannedRoute.Name              = viewModel.Name;
                plannedRoute.RouteTypeId       = viewModel.RouteTypeId;
                plannedRoute.TransportTypeId   = viewModel.TransportTypeId;
                plannedRoute.Description       = viewModel.Description;
                plannedRoute.StartHour         = viewModel.StartHour;
                plannedRoute.EstimatedDuration = viewModel.EstimatedDuration;
                plannedRoute.TotalDistance     = viewModel.TotalDistance;
                plannedRoute.RouteDayOfTheWeek = viewModel.RouteDayOfTheWeek;
                plannedRoute.Active            = viewModel.Active;
                plannedRoute.IsDeleted         = viewModel.IsDeleted;


                // audit
                //plannedRoute.CreateBy = UserInfo.UserID;
                //plannedRoute.UpdateBy = UserInfo.UserID;
                plannedRoute.CreateOn = DateTime.UtcNow;
                plannedRoute.UpdateOn = DateTime.UtcNow;

                // add
                log.Debug("_plannedRouteService.AddPlannedRoute - " + PlannedRouteDTO.FormatPlannedRouteDTO(plannedRoute));

                int id = _plannedRouteService.AddPlannedRoute(plannedRoute);

                plannedRoute.PlannedRouteId = id;

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

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

                throw;
            }
        }
Example #3
0
        //[ValidateAntiForgeryToken]
        public JsonResult SaveList(PlannedRouteViewModel[] viewModels, int?itemId)
        {
            try
            {
                log.Debug("SaveList");

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

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

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

                throw;
            }
        }
Example #4
0
        public ActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_plannedRouteService.GetPlannedRoute - plannedRouteId: " + id + " ");

                var plannedRoute = new PlannedRouteViewModel(_plannedRouteService.GetPlannedRoute(id));

                log.Debug("_plannedRouteService.GetPlannedRoute - " + PlannedRouteViewModel.FormatPlannedRouteViewModel(plannedRoute));

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

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

                throw;
            }
        }