Beispiel #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();
        }
Beispiel #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();
            }
        }
Beispiel #3
0
        public Courier GetCourierWithUsernameAndPassword(UsernameAndPasswordDto userInfo)
        {
            var hashedPassword = PasswordHelper.HashString(userInfo.Password, userInfo.Username);
            var courier        =
                _courierRepository.FirstOrDefault(
                    o => o.User.UserName == userInfo.Username && o.User.Password == hashedPassword);

            if (courier != null)
            {
                if (String.IsNullOrEmpty(courier.Imei) || courier.Imei.Equals(userInfo.Imei))
                {
                    courier.Imei   = userInfo.Imei;
                    courier.Status = (int)StatusCourier.Online;
                    _courierRepository.Update(courier);
                    //add system event
                    _systemEventRepository.Add(EventMessage.CourierLogin, new Dictionary <EventMessageParam, string> {
                        { EventMessageParam.Courier, courier.User.FullName }
                    });
                    _courierRepository.Commit();
                }
            }
            return(courier);
        }
Beispiel #4
0
 public void Add(EventMessage eventMessage, Dictionary <EventMessageParam, string> dictionParam)
 {
     _systemEventRepository.Add(eventMessage, dictionParam);
 }