Ejemplo n.º 1
0
        public void AddListRequestForService(IList <Request> listRequest)
        {
            var currentDate = DateTime.UtcNow;

            foreach (var req in listRequest)
            {
                var req1 = req;
                if (!_requestRepository.CheckExist(
                        p =>
                        p.CreatedOn.Value.Year == currentDate.Year && p.CreatedOn.Value.Month == currentDate.Month &&
                        p.CreatedOn.Value.Day == currentDate.Day &&
                        p.HistoryScheduleId == req1.HistoryScheduleId))
                {
                    req.RequestNo = _staticValueService.GetNewRequestNumber();

                    //Tinh estimate distance, estimate time
                    var estimateDistance = 0;
                    var estimateTime     = 0;
                    if (req.LocationFrom > 0 && req.LocationTo > 0)
                    {
                        var fromLocation = _locationRepository.GetById(req.LocationFrom);
                        var fromPoint    = new GoogleMapPoint
                        {
                            Lat = fromLocation.Lat.GetValueOrDefault(),
                            Lng = fromLocation.Lng.GetValueOrDefault()
                        };

                        var toLocation = _locationRepository.GetById(req.LocationTo);
                        var toPoint    = new GoogleMapPoint
                        {
                            Lat = toLocation.Lat.GetValueOrDefault(),
                            Lng = toLocation.Lng.GetValueOrDefault()
                        };
                        var dataGoogle = _googleService.GetDistance(fromPoint, toPoint);
                        if (dataGoogle.status == "OK")
                        {
                            if (dataGoogle.rows[0].elements[0].status == "OK")
                            {
                                estimateDistance = dataGoogle.rows[0].elements[0].distance.value;
                                estimateTime     = dataGoogle.rows[0].elements[0].duration.value;
                            }
                        }
                    }
                    req.EstimateTime     = estimateTime;
                    req.EstimateDistance = estimateDistance;
                    Repository.Add(req);
                    var courier = _courierRepository.GetById(req.CourierId.GetValueOrDefault()).User;

                    _systemEventRepository.Add(EventMessage.RequestCreated,
                                               new Dictionary <EventMessageParam, string>()
                    {
                        { EventMessageParam.Request, req.RequestNo },
                        { EventMessageParam.Courier, courier.LastName + " " + courier.FirstName + (string.IsNullOrEmpty(courier.MiddleName) ? "" : " " + courier.MiddleName) },
                    });
                }
            }
            Repository.Commit();
        }
Ejemplo n.º 2
0
        public void SendHoldingRequest(SendHoldingRequestItemVo holdingRequestItem)
        {
            using (var tran = new TransactionScope())
            {
                var holdingRequest = GetById(holdingRequestItem.HoldingRequestSelectedId);

                var request = new Request()
                {
                    RequestNo       = _staticValueService.GetNewRequestNumber(),
                    LocationFrom    = holdingRequest.LocationFrom,
                    LocationTo      = holdingRequest.LocationTo,
                    StartTime       = holdingRequest.StartTime.GetValueOrDefault(),
                    EndTime         = holdingRequest.EndTime.GetValueOrDefault(),
                    SendingTime     = holdingRequestItem.IsStat ? DateTime.UtcNow : holdingRequestItem.SendingTime,
                    IsStat          = holdingRequestItem.IsStat,
                    Status          = (int)StatusRequest.NotSent,
                    CourierId       = holdingRequestItem.CourierId,
                    Description     = holdingRequest.Description,
                    ExpiredTime     = holdingRequestItem.ExpiredTime,
                    SaveSystemEvent = false
                };


                _requestService.Add(request);

                _holdingRequestRepository.Delete(holdingRequest);
                _holdingRequestRepository.Commit();


                _systemEventRepository.Add(EventMessage.RequestCreated, new Dictionary <EventMessageParam, string>()
                {
                    { EventMessageParam.Request, request.RequestNo },
                    { EventMessageParam.Courier, _courierRepository.GetById(holdingRequestItem.CourierId.GetValueOrDefault()).User.UserName }
                });



                tran.Complete();
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(RequestParameter parameters)
        {
            var viewModel = MapFromClientParameters(parameters);
            var entity    = viewModel.MapTo <Request>();

            if (entity.CourierId > 0)
            {
                var courier = _userService.GetById(entity.CourierId.GetValueOrDefault());
                if (courier.IsActive == false)
                {
                    throw new Exception("Cannot assign request to inactive courier");
                }
            }

            if (entity.IsStat == true)
            {
                entity.Status      = (int)StatusRequest.Sent;
                entity.SendingTime = DateTime.UtcNow;
            }
            else
            {
                entity.Status = (int)StatusRequest.NotSent;
            }
            entity.RequestNo = _staticValueService.GetNewRequestNumber();

            //Tinh estimate distance, estimate time
            var estimateDistance = 0;
            var estimateTime     = 0;

            if (entity.LocationFrom > 0 && entity.LocationTo > 0)
            {
                var fromLocation = _locationService.GetById(entity.LocationFrom);
                var fromPoint    = new GoogleMapPoint
                {
                    Lat = fromLocation.Lat.GetValueOrDefault(),
                    Lng = fromLocation.Lng.GetValueOrDefault()
                };

                var toLocation = _locationService.GetById(entity.LocationTo);
                var toPoint    = new GoogleMapPoint
                {
                    Lat = toLocation.Lat.GetValueOrDefault(),
                    Lng = toLocation.Lng.GetValueOrDefault()
                };
                var dataGoogle = _googleService.GetDistance(fromPoint, toPoint);
                if (dataGoogle.status == "OK")
                {
                    if (dataGoogle.rows[0].elements[0].status == "OK")
                    {
                        estimateDistance = dataGoogle.rows[0].elements[0].distance.value;
                        estimateTime     = dataGoogle.rows[0].elements[0].duration.value;
                    }
                }
            }

            entity.EstimateDistance = estimateDistance;
            entity.EstimateTime     = estimateTime;
            Request savedEntity;

            using (var transaction = new TransactionScope())
            {
                savedEntity = MasterFileService.Add(entity);
                if (viewModel.SharedViewModel is DashboardRequestShareViewModel)
                {
                    var holdingRequestId = ((DashboardRequestShareViewModel)viewModel.SharedViewModel).HoldingRequestId;
                    if (holdingRequestId.GetValueOrDefault() > 0)
                    {
                        _holdingRequestService.DeleteById(holdingRequestId.GetValueOrDefault());
                    }
                }
                transaction.Complete();
            }

            if (savedEntity != null)
            {
                return(Json(new { savedEntity.WarningInfo, savedEntity.Id }, JsonRequestBehavior.DenyGet));
            }
            return(Json(1, JsonRequestBehavior.DenyGet));
        }