public async Task <bool> EditRoute(EditRouteViewModel model)
        {
            var arrivalPlace   = _locationServices.GetLocation(model.ArrivalPlaceId);
            var departurePlace = _locationServices.GetLocation(model.DeparturePlaceId);
            var routeEdit      = GetRoute(model.RouteId);

            //map new data to route
            if (arrivalPlace != null && departurePlace != null && routeEdit != null)
            {
                try
                {
                    _context.Attach(routeEdit);
                    routeEdit.DeparturePlaceId = departurePlace.LocationId;
                    routeEdit.DeparturePlace   = departurePlace.LocationName;
                    routeEdit.ArrivalPlaceId   = arrivalPlace.LocationId;
                    routeEdit.ArrivalPlace     = arrivalPlace.LocationName;
                    var result = await _context.SaveChangesAsync();

                    return(result > 0);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(false);
        }
Example #2
0
        public async Task <IActionResult> Create(CreateRouteViewModel model)
        {
            string message = String.Empty;

            if (ModelState.IsValid)
            {
                if (model.ArrivalPlaceId == model.DeparturePlaceId)
                {
                    message = "Địa điểm xuất phát và địa điểm đến không được trùng nhau";
                    TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message);
                    return(RedirectToAction(actionName: "Index"));
                }
                if (model.Distance <= 0)
                {
                    message = "Chiều dài tuyến đường phải lớn hơn 0";
                    TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message);
                    return(RedirectToAction(actionName: "Index"));
                }
                if (_routeServices.IsRouteExists(departureId: model.DeparturePlaceId, arrivalId: model.ArrivalPlaceId))
                {
                    message = "Đã tồn tại tuyến đường vận chuyển này";
                    TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message);
                    return(RedirectToAction(actionName: "Index"));
                }
                var arrivalPlace          = _locationServices.GetLocation(model.ArrivalPlaceId);
                var departurePlace        = _locationServices.GetLocation(model.DeparturePlaceId);
                RouteInformation newRoute = new RouteInformation()
                {
                    RouteId          = Guid.NewGuid().ToString(),
                    ArrivalPlace     = arrivalPlace.LocationName,
                    DeparturePlace   = departurePlace.LocationName,
                    ArrivalPlaceId   = model.ArrivalPlaceId,
                    DeparturePlaceId = model.DeparturePlaceId,
                    Distance         = model.Distance
                };
                if (await _routeServices.CreateRoute(newRoute))
                {
                    message = "Tuyến vận chuyển được tạo";
                    TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Success, message);
                    return(RedirectToAction(actionName: "Index"));
                }
            }
            message = "Lỗi không xác định, xin mời thao tác lại";
            TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message);
            return(RedirectToAction(actionName: "Index"));
        }
Example #3
0
 public ActionResult GetLocation(long id)
 {
     try{
         return(Ok(_locationService.GetLocation(id)));
     }catch (Exception e) {
         return(BadRequest(e.Message));
     }
 }
        private List <Location> Update(List <LocationExt> toUpdateList)
        {
            List <Location> updateObj = new List <Location>();

            foreach (var u in toUpdateList)
            {
                var country = LocationServices.GetLocation(u.ID);
                if (country != null && country.LocationDesc != u.LocationDesc)
                {
                    country.LocationDesc = u.LocationDesc;
                    country.ModifiedOn   = DateTime.Now;
                    country.ModifiedBy   = AuthenticatedUser;
                }
                updateObj.Add(country);
            }
            return(updateObj);
        }
Example #5
0
        public async Task <IActionResult> Delete(string locationId)
        {
            var locationDel = _locationServices.GetLocation(locationId);

            if (await _locationServices.DeleteLocation(locationDel))
            {
                var userMessage = new MessageVM()
                {
                    CssClassName = "alert alert-success ", Title = "Thành công", Message = "Đã xóa địa điểm thành công"
                };
                TempData["UserMessage"] = JsonConvert.SerializeObject(userMessage);
            }
            else
            {
                var userMessage = new MessageVM()
                {
                    CssClassName = "alert alert-danger", Title = "Không thành công", Message = "Đã có lỗi khi thao tác, xin mời thử lại"
                };
                TempData["UserMessage"] = JsonConvert.SerializeObject(userMessage);
            }
            return(RedirectToAction(actionName: "Index", controllerName: "Location"));
        }
Example #6
0
 public IActionResult GetLocationList(GridOptions options)
 {
     return(Ok(_locationServices.GetLocation(options)));
 }