Пример #1
0
        public async Task SetStatusCompletPoint(int idOrderMobile)
        {
            ManagerNotifyMobileApi managerNotifyMobileApi = new ManagerNotifyMobileApi();
            OrderMobile            orderMobile            = context.OrderMobiles
                                                            .Include(om => om.Orders)
                                                            .Include(om => om.OnePointForAddressOrders)
                                                            .FirstOrDefault(om => om.ID == idOrderMobile);
            OnePointForAddressOrder onePointForAddressOrder = orderMobile.OnePointForAddressOrders.FirstOrDefault(om => om.Status == "DriveFromPoint");
            int   index = orderMobile.OnePointForAddressOrders.IndexOf(onePointForAddressOrder);
            Order order = context.Orders.FirstOrDefault(o => o.ID == onePointForAddressOrder.IDorder);

            if (onePointForAddressOrder != null)
            {
                orderMobile.OnePointForAddressOrders.First(om => om.Status == "DriveFromPoint").Status = "CompletePoint";
                orderMobile.OnePointForAddressOrders[index + 1].Status = "DriveFromPoint";
            }
            if (onePointForAddressOrder.Type == "Start")
            {
                order.CurrentStatus = "Picked up";
            }
            else if (onePointForAddressOrder.Type == "End")
            {
                order.CurrentStatus = "Delivered";
            }
            string tokenShope = GetTokenShope(orderMobile.IdDriver);

            managerNotifyMobileApi.SendNotyfyStatusPickup(tokenShope, "Order", $"Drive to {orderMobile.OnePointForAddressOrders[index+1].Address}", $"It is important to complete the order on time before {orderMobile.OnePointForAddressOrders[index+1].PTime}");
            await context.SaveChangesAsync();
        }
Пример #2
0
        public string GetOrderMobile(string token)
        {
            string respons = null;

            if (token == null || token == "")
            {
                return(JsonConvert.SerializeObject(new ResponseAppS("failed", "1", null)));
            }
            try
            {
                OrderMobile orderMobile = null;
                bool        isToken     = ManagerMobileApi.CheckToken(token);
                if (isToken)
                {
                    orderMobile = ManagerMobileApi.GetOrderMobile(token);
                    respons     = JsonConvert.SerializeObject(new ResponseAppS("success", null, orderMobile));
                }
                else
                {
                    respons = JsonConvert.SerializeObject(new ResponseAppS("failed", "2", null));
                }
            }
            catch (Exception)
            {
                respons = JsonConvert.SerializeObject(new ResponseAppS("failed", "Technical work on the service", null));
            }
            return(respons);
        }
Пример #3
0
        public IActionResult SaveOrderMobile()
        {
            IActionResult actionResult = null;

            try
            {
                string key = null;
                ViewBag.BaseUrl = Config.BaseReqvesteUrl;
                Request.Cookies.TryGetValue("KeyAvthoTaxi", out key);
                if (managerTaxi.CheckKey(key) && OrderMobile != null)
                {
                    managerTaxi.SetMobileOrder(OrderMobile);
                    actionResult = Redirect(Config.BaseReqvesteUrl);
                    OrderMobile  = null;
                }
                else
                {
                    actionResult = Redirect(Config.BaseReqvesteUrl);
                }
            }
            catch (Exception)
            {
                OrderMobile = null;
            }
            return(actionResult);
        }
Пример #4
0
        public int OrederMobile(string token, ref string description, ref OrderMobile orderMobile)
        {
            IRestResponse response = null;
            string        content  = null;

            try
            {
                RestClient  client  = new RestClient(Config.BaseReqvesteUrl);
                RestRequest request = new RestRequest("Api.Mobile/OrderMobile", Method.POST);
                client.Timeout = 20000;
                request.AddHeader("Accept", "application/json");
                request.AddParameter("token", token);
                response = client.Execute(request);
                content  = response.Content;
            }
            catch (Exception)
            {
                return(4);
            }
            if (content == "" || response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                return(4);
            }
            else
            {
                return(GetData(content, ref description, ref orderMobile));
            }
        }
Пример #5
0
        public string OrderInitAndInsert(string idDriver, string idOrder)
        {
            string actionResult = null;

            try
            {
                string key = null;
                ViewBag.BaseUrl = Config.BaseReqvesteUrl;
                Request.Cookies.TryGetValue("KeyAvthoTaxi", out key);
                if (managerTaxi.CheckKey(key) && OrderMobile != null)
                {
                    Order        order  = managerTaxi.GetOrder(idOrder);
                    List <Order> orders = managerTaxi.GetOrdersSuitableAndInsert(idDriver, OrderMobile, order);
                    actionResult = JsonConvert.SerializeObject(orders);
                }
                else
                {
                    actionResult = JsonConvert.SerializeObject(new List <Order>());
                }
            }
            catch (Exception)
            {
                OrderMobile = null;
            }
            return(actionResult);
        }
Пример #6
0
        public IActionResult OrderAssigne(string idDriver)
        {
            IActionResult actionResult = null;

            try
            {
                string key = null;
                ViewBag.BaseUrl = Config.BaseReqvesteUrl;
                Request.Cookies.TryGetValue("KeyAvthoTaxi", out key);
                if (managerTaxi.CheckKey(key))
                {
                    OrderMobile = new OrderMobile();
                    Driver driver = managerTaxi.GetDriver(idDriver);
                    OrderMobile.IdDriver = driver.ID.ToString();
                    ViewBag.Driver       = driver;
                    actionResult         = View("AssignePage");
                }
                else
                {
                    if (Request.Cookies.ContainsKey("KeyAvthoTaxi"))
                    {
                        Response.Cookies.Delete("KeyAvthoTaxi");
                    }
                    OrderMobile  = null;
                    actionResult = Redirect(Config.BaseReqvesteUrl);
                }
            }
            catch (Exception)
            {
                OrderMobile = null;
            }
            return(actionResult);
        }
Пример #7
0
 private static int GetData(string respJsonStr, ref OrderMobile orderMobile)
 {
     try
     {
         respJsonStr = respJsonStr.Replace("\\", "");
         respJsonStr = respJsonStr.Remove(0, 1);
         respJsonStr = respJsonStr.Remove(respJsonStr.Length - 1);
         var    responseAppS = JObject.Parse(respJsonStr);
         string status       = responseAppS.Value <string>("Status");
         if (status == "success")
         {
             orderMobile = JsonConvert.DeserializeObject <OrderMobile>(responseAppS.
                                                                       SelectToken("ResponseStr").ToString());
             return(3);
         }
         else
         {
             return(2);
         }
     }
     catch
     {
         return(2);
     }
 }
Пример #8
0
        public async void SetMobileOrder(OrderMobile orderMobile)
        {
            await sqlCommand.AssigneOrderMobile(orderMobile);

            ManagerNotifyMobileApi managerNotifyMobileApi = new ManagerNotifyMobileApi();
            string tokenShope = sqlCommand.GetTokenShope(orderMobile.IdDriver);

            managerNotifyMobileApi.SendNotyfyStatusPickup(tokenShope, "Order", "New order for you", "Dispatcher gave you a new order, The dispatcher gave you a new order, accept the order if possible, if you have no orders, accept the order within 5 minutes");
        }
Пример #9
0
 public void StartGeofence(OrderMobile orderMobile)
 {
     if (gefenceModel == null)
     {
         gefenceModel = new GefenceModel();
     }
     gefenceModel.OrderMobile             = orderMobile;
     gefenceModel.OnePointForAddressOrder = orderMobile.OnePointForAddressOrders[0];
     gefenceModel.IsNewOrder = false;
     UpdateLocation();
 }
Пример #10
0
        public async Task SetOrederMobile(OrderMobile orderMobile, string idDrigver, bool isNew)
        {
            Driver driver = context.Drivers.FirstOrDefault(d => d.ID.ToString() == idDrigver);

            orderMobile.Status = isNew ? "New" : "NewNext";
            foreach (Order order in orderMobile.Orders)
            {
                Order order1 = context.Orders.FirstOrDefault(o => o.ID == order.ID);
                order.CurrentStatus = "Assigned";
                order1.Driver       = driver;
            }
            context.OrderMobiles.Add(orderMobile);
            await context.SaveChangesAsync();
        }
Пример #11
0
 public void StartGeofence(OrderMobile orderMobile)
 {
     if (gefenceModel == null)
     {
         gefenceModel = new GefenceModel();
     }
     gefenceModel.OrderMobile             = orderMobile;
     gefenceModel.OnePointForAddressOrder = orderMobile.OnePointForAddressOrders[0];
     gefenceModel.IsNewOrder = false;
     Dexter.WithActivity(MainActivity.GetInstance())
     .WithPermission(Manifest.Permission.AccessFineLocation)
     .WithListener(this)
     .Check();
 }
Пример #12
0
        public async Task <BackgroundService.DriverManager.location> GetAddressToOrderDB(int idMobileOrder)
        {
            OrderMobile orderMobile = await context.OrderMobiles
                                      .Include(o => o.OnePointForAddressOrders)
                                      .FirstOrDefaultAsync(o => o.ID == idMobileOrder);

            OnePointForAddressOrder onePointForAddressOrder = orderMobile.OnePointForAddressOrders[orderMobile.OnePointForAddressOrders.Count - 1];

            return(new ApiMobaileTaxi.BackgroundService.DriverManager.location(onePointForAddressOrder.Lat, onePointForAddressOrder.Lng)
            {
                ID = orderMobile.IdDriver,
                ApiniTime = onePointForAddressOrder.PTime,
                Date = onePointForAddressOrder.Date
            });
        }
Пример #13
0
        public int OrderWork(string typeOrder, string token, ref string description, ref OrderMobile orderMobile)
        {
            orderGet = new OrderGet();
            int stateOrder = 1;

            if (CrossConnectivity.Current.IsConnected)
            {
                if (typeOrder == "OrderMobileGet")
                {
                    stateOrder = orderGet.OrederMobile(token, ref description, ref orderMobile);
                }
            }
            orderGet = null;
            return(stateOrder);
        }
Пример #14
0
        public async Task AssigneOrderMobile(OrderMobile orderMobile)
        {
            Driver       driver = context.Drivers.FirstOrDefault(d => d.ID.ToString() == orderMobile.IdDriver);
            List <Order> orders = orderMobile.Orders;

            orderMobile.Status = "New";
            orderMobile.Orders = new List <Order>();
            foreach (Order order in orders)
            {
                Order order1 = context.Orders.FirstOrDefault(o => o.ID == order.ID);
                order1.CurrentStatus = "Assigned";
                order1.Driver        = driver;
                orderMobile.Orders.Add(order1);
            }
            context.OrderMobiles.Add(orderMobile);
            await context.SaveChangesAsync();
        }
Пример #15
0
        public async Task SetStatusMobileOrderStart(int idOrderMobile)
        {
            ManagerNotifyMobileApi managerNotifyMobileApi = new ManagerNotifyMobileApi();
            OrderMobile            orderMobile            = context.OrderMobiles
                                                            .Include(om => om.Orders)
                                                            .Include(om => om.OnePointForAddressOrders)
                                                            .FirstOrDefault(om => om.ID == idOrderMobile);
            Order order = context.Orders.FirstOrDefault(o => o.ID == orderMobile.OnePointForAddressOrders[0].IDorder);

            orderMobile.Status = "InWork";
            orderMobile.OnePointForAddressOrders[0].Status = "DriveFromPoint";
            order.CurrentStatus = "Picked up";
            string tokenShope = GetTokenShope(orderMobile.IdDriver);

            managerNotifyMobileApi.SendNotyfyStatusPickup(tokenShope, "Order", $"Drive to {orderMobile.OnePointForAddressOrders[0].Address}", $"It is important to complete the order on time before {orderMobile.OnePointForAddressOrders[0].PTime}");
            await context.SaveChangesAsync();
        }
Пример #16
0
        public List <Order> SuitableOrders(string idDriver, OrderMobile orderMobile = null, Order order1 = null)
        {
            List <Model.Location> locationsOrder = new List <Model.Location>();

            Model.Location locationsDriver = null;
            Driver         driver          = sqlCommand.GetDriver(idDriver);
            List <Order>   orders          = sqlCommand.GetOrders();

            Model.Location locationDriveZip = connectorApiMaps.GetGetLonAndLanToAddress(driver.ZipCod.ToString());
            if (locationDriveZip != null)
            {
                locationDriveZip.ID = driver.ID.ToString();
                locationsDriver     = locationDriveZip;
            }
            foreach (var order in orders)
            {
                Model.Location locationOrder = connectorApiMaps.GetGetLonAndLanToAddress(order.FromAddress.ToString());
                Model.Location location1     = connectorApiMaps.GetGetLonAndLanToAddress(order.ToAddress.ToString());
                if (locationOrder != null)
                {
                    locationOrder.ID             = order.ID.ToString();
                    locationOrder.Date           = order.Date;
                    locationOrder.PickuoTime     = order.TimeOfPickup;
                    locationOrder.ApiniTime      = order.TimeOfAppointment;
                    locationOrder.ApiniTime      = order.TimeOfAppointment;
                    locationOrder.latE           = location1.lat;
                    locationOrder.lngE           = location1.lng;
                    locationOrder.CountCusstomer = order.CountCustomer;
                    locationsOrder.Add(locationOrder);
                }
            }
            if ((locationsOrder != null && locationsOrder.Count != 0) && locationsDriver != null)
            {
                if (orderMobile == null && order1 == null)
                {
                    return(GetSuitableOrders(locationsOrder, locationsDriver, orders));
                }
                else
                {
                    return(InsertOrderAndPointAddres(orderMobile, order1, locationsOrder, locationsDriver, orders));
                }
            }
            return(new List <Order>());
        }
Пример #17
0
        public static bool ResetGeofnceModel()
        {
            string        token       = CrossSettings.Current.GetValueOrDefault("Token", "");
            OrderMobile   orderMobile = null;
            IRestResponse response    = null;
            string        content     = null;

            try
            {
                RestClient  client  = new RestClient(Config.BaseReqvesteUrl);
                RestRequest request = new RestRequest("Api.Mobile/OrderMobile", Method.POST);
                client.Timeout = 60000;
                request.AddHeader("Accept", "application/json");
                request.AddParameter("token", token);
                response = client.Execute(request);
                content  = response.Content;
            }
            catch (Exception)
            {
                return(false);
            }
            if (content == "" || response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                return(false);
            }
            else
            {
                if (GetData(content, ref orderMobile) == 3)
                {
                    if (gefenceModel == null)
                    {
                        gefenceModel = new GefenceModel();
                    }
                    gefenceModel.OrderMobile             = orderMobile;
                    gefenceModel.OnePointForAddressOrder = orderMobile.OnePointForAddressOrders.FirstOrDefault(oP => oP.Status == "DriveFromPoint");
                    gefenceModel.IsNewOrder = false;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #18
0
        private List <Order> InsertOrderAndPointAddres(OrderMobile orderMobile, Order order, List <Model.Location> locationsOrder, Model.Location locationDriver, List <Order> orders)
        {
            int positionS     = 0;
            int positionE     = 0;
            int numberOfSeats = 4;

            orderMobile.Status = "New";
            if (orderMobile.OnePointForAddressOrders == null || orderMobile.OnePointForAddressOrders.Count == 0)
            {
                orderMobile.OnePointForAddressOrders = new List <OnePointForAddressOrder>();
                Model.Location location = locationsOrder.Find(l => l.ID == order.ID.ToString());
                orderMobile.OnePointForAddressOrders.Add(new OnePointForAddressOrder(order.ID, location.lat, location.lng, order.TimeOfPickup, order.Date, "Start", order.FromAddress));
                orderMobile.OnePointForAddressOrders.Add(new OnePointForAddressOrder(order.ID, location.latE, location.lngE, order.TimeOfAppointment, order.Date, "End", order.ToAddress));
            }
            else
            {
                Model.Location location  = locationsOrder.Find(l => l.ID == order.ID.ToString());
                Model.Location location1 = new Model.Location(location.latE, location.lngE);
                GetPositionLocation(orderMobile.OnePointForAddressOrders, location, locationDriver, ref positionS);
                orderMobile.OnePointForAddressOrders.Insert(positionS, new OnePointForAddressOrder(order.ID, location.lat, location.lng, order.TimeOfPickup, order.Date, "Start", order.FromAddress));
                GetPositionLocation(orderMobile.OnePointForAddressOrders, location1, locationDriver, ref positionE);
                orderMobile.OnePointForAddressOrders.Insert(positionE, new OnePointForAddressOrder(order.ID, location.latE, location.lngE, order.TimeOfAppointment, order.Date, "End", order.ToAddress));
                orderMobile.OnePointForAddressOrders.Sort((b1, b2) => DateTime.Compare(DateTime.Parse(b1.PTime), DateTime.Parse(b2.PTime)));
            }
            if (orderMobile.Orders == null)
            {
                orderMobile.Orders = new List <Order>();
            }
            orderMobile.Orders.Add(order);
            foreach (Order order1 in orderMobile.Orders)
            {
                numberOfSeats -= order1.CountCustomer;
                if (locationsOrder.FirstOrDefault(l => l.ID == order1.ID.ToString()) != null)
                {
                    locationsOrder.Remove(locationsOrder.Find(l => l.ID == order1.ID.ToString()));
                }
            }
            if (locationsOrder != null && locationsOrder.Count != 0 && numberOfSeats > 0)
            {
                return(OrderOnTheWay(locationsOrder, locationDriver, orderMobile, orders, numberOfSeats));
            }
            return(new List <Order>());
        }
Пример #19
0
        public string GetOrderMobile(string idDriver, string idOrder)
        {
            string actionResult = null;

            try
            {
                string key = null;
                ViewBag.BaseUrl = Config.BaseReqvesteUrl;
                Request.Cookies.TryGetValue("KeyAvthoTaxi", out key);
                if (managerTaxi.CheckKey(key) && OrderMobile != null)
                {
                    actionResult = JsonConvert.SerializeObject(OrderMobile);
                }
                else
                {
                    actionResult = JsonConvert.SerializeObject(new List <Order>());
                }
            }
            catch (Exception)
            {
                OrderMobile = null;
            }
            return(actionResult);
        }
Пример #20
0
        public async Task SetStatusMobileOrderEnd(int idOrderMobile, string token)
        {
            ManagerNotifyMobileApi managerNotifyMobileApi = new ManagerNotifyMobileApi();
            Driver      driver       = context.Drivers.FirstOrDefault(d => d.Token == token);
            OrderMobile orderMobile1 = context.OrderMobiles.ToList().FirstOrDefault(om => om.IdDriver == driver.ID.ToString() && om.Status == "NewNext");
            OrderMobile orderMobile  = context.OrderMobiles
                                       .Include(om => om.Orders)
                                       .Include(om => om.OnePointForAddressOrders)
                                       .FirstOrDefault(om => om.ID == idOrderMobile);

            if (orderMobile1 != null)
            {
                orderMobile1.Status = "New";
            }
            Order order = context.Orders.FirstOrDefault(o => o.ID == orderMobile.OnePointForAddressOrders[orderMobile.OnePointForAddressOrders.Count - 1].IDorder);

            orderMobile.Status = "EndWork";
            orderMobile.OnePointForAddressOrders[0].Status = "CompletePoint";
            order.CurrentStatus = "Delivered";
            string tokenShope = GetTokenShope(orderMobile.IdDriver);

            managerNotifyMobileApi.SendNotyfyStatusPickup(tokenShope, "Order", "You have successfully completed the order", $"accept the next order on time. within 5 minutes, if any");
            await context.SaveChangesAsync();
        }
Пример #21
0
        public async void OrderOnTheWay(List <location> locationsOrder, List <location> locationsAcceptOrder, List <Order> orders, SqlCoommandTaxiApi sqlCoommandTaxiApi, bool isNew = true, OrderMobile orderMobile = null)
        {
            if (connectorApiMaps == null)
            {
                connectorApiMaps        = new ConnectorApiMaps();
                this.sqlCoommandTaxiApi = sqlCoommandTaxiApi;
            }
            int numberOfSeats = 4;

            orderMobile = new OrderMobile();
            orderMobile.OnePointForAddressOrders = new List <OnePointForAddressOrder>();
            orderMobile.Status = "New";
            Order order = orders.Find(o => o.ID.ToString() == locationsAcceptOrder[1].ID);

            orderMobile.OnePointForAddressOrders.Add(new OnePointForAddressOrder(order.ID, locationsAcceptOrder[1].lat, locationsAcceptOrder[1].lng, order.TimeOfPickup, order.Date, "Start", order.FromAddress));
            orderMobile.OnePointForAddressOrders.Add(new OnePointForAddressOrder(order.ID, locationsAcceptOrder[1].latE, locationsAcceptOrder[1].lngE, order.TimeOfAppointment, order.Date, "End", order.ToAddress));
            orderMobile.Orders   = new List <Order>();
            orderMobile.IdDriver = locationsAcceptOrder[0].ID;
            orderMobile.Orders.Add(order);
            numberOfSeats -= orders.Find(o => o.ID.ToString() == locationsAcceptOrder[1].ID).CountCustomer;
            List <Steps> steps = connectorApiMaps.GetGetDirections($"{ConvertTOString(locationsAcceptOrder[1].lat)},{ConvertTOString(locationsAcceptOrder[1].lng)}", $"{ConvertTOString(locationsAcceptOrder[1].latE)},{ConvertTOString(locationsAcceptOrder[1].lngE)}");

            if (orderMobile.Orders == null)
            {
                orderMobile.Orders = new List <Order>();
            }
            if (numberOfSeats > 0)
            {
                for (int i = 0; i < locationsOrder.Count; i++)
                {
                    if (locationsOrder[i].CountCusstomer > numberOfSeats)
                    {
                        continue;
                    }
                    bool   isAddOrder      = true;
                    bool   isOnTheWay      = false;
                    int    positionS       = 0;
                    int    positionE       = 0;
                    bool   isOnTheWayStart = false;
                    double lat             = 0;
                    double lng             = 0;
                    double latF            = locationsOrder[i].lat;
                    double lngF            = locationsOrder[i].lng;
                    foreach (Steps step in steps)
                    {
                        if (locationsOrder[i].CountCusstomer > numberOfSeats)
                        {
                            break;
                        }
                        List <OnePointForAddressOrder> onePointForAddressOrders = new List <OnePointForAddressOrder>();
                        onePointForAddressOrders.AddRange(orderMobile.OnePointForAddressOrders);
                        double tmpLoc = Convert.ToDouble(step.end_location.lat - step.start_location.lat);
                        lat    = step.start_location.lat + tmpLoc;
                        tmpLoc = step.end_location.lng - step.start_location.lng;
                        lng    = step.start_location.lng + tmpLoc;
                        if ((latF - 0.013 < lat && lat + 0.013 > latF) &&
                            (lngF - 0.013 < lng && lng + 0.013 > lngF) && !isOnTheWayStart)
                        {
                            location locationNewS = new location(locationsOrder[i].lat, locationsOrder[i].lng);
                            location locationNewE = new location(locationsOrder[i].latE, locationsOrder[i].lngE);
                            GetPositionLocation(onePointForAddressOrders, locationNewS, locationsAcceptOrder[0], ref positionS);
                            Order order1 = orders.Find(o => o.ID.ToString() == locationsOrder[i].ID);
                            onePointForAddressOrders.Insert(positionS, new OnePointForAddressOrder(order1.ID, locationsOrder[i].lat, locationsOrder[i].lng, order1.TimeOfPickup, order1.Date, "Start", order1.FromAddress));
                            if (GetEndOrderOnTheWay(steps.GetRange(steps.IndexOf(step), (steps.Count - 1) - steps.IndexOf(step)), locationsOrder[i]))
                            {
                                GetPositionLocation(onePointForAddressOrders, locationNewE, locationsAcceptOrder[0], ref positionE);
                                onePointForAddressOrders.Insert(positionE, new OnePointForAddressOrder(order1.ID, locationsOrder[i].latE, locationsOrder[i].lngE, order1.TimeOfAppointment, order1.Date, "End", order1.ToAddress));
                            }
                            else
                            {
                                onePointForAddressOrders.Add(new OnePointForAddressOrder(order1.ID, locationsOrder[i].latE, locationsOrder[i].lngE, order1.TimeOfAppointment, order1.Date, "End", order1.ToAddress));
                                isOnTheWay = true;
                            }
                            int duration = connectorApiMaps.GetGetDuration($"{ConvertTOString(locationsAcceptOrder[0].lat)},{ConvertTOString(locationsAcceptOrder[0].lng)}", $"{ConvertTOString(onePointForAddressOrders[0].Lat)},{ConvertTOString(onePointForAddressOrders[0].Lng)}");
                            if (DateTime.Now.AddSeconds(duration).AddMinutes(-20) < DateTime.Parse($"{GetDFormat(onePointForAddressOrders[0].Date)} {onePointForAddressOrders[0].PTime}"))
                            {
                                for (int j = 1; j < onePointForAddressOrders.Count; j++)
                                {
                                    DateTime dateTime  = new DateTime();
                                    DateTime dateTime1 = new DateTime();
                                    int      duration1 = connectorApiMaps.GetGetDuration($"{ConvertTOString(onePointForAddressOrders[j - 1].Lat)},{ConvertTOString(onePointForAddressOrders[j - 1].Lng)}", $"{ConvertTOString(onePointForAddressOrders[j].Lat)},{ConvertTOString(onePointForAddressOrders[j].Lng)}");
                                    if (duration1 < 60 * 10)
                                    {
                                        continue;
                                    }
                                    if (onePointForAddressOrders[j - 1].Type == "Start")
                                    {
                                        dateTime = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j - 1].Date)} {onePointForAddressOrders[j - 1].PTime}");
                                    }
                                    else if (onePointForAddressOrders[j - 1].Type == "End")
                                    {
                                        var    date  = orders.Find(o => o.ID == onePointForAddressOrders[j - 1].IDorder);
                                        string date1 = date.TimeOfAppointment != null ? date.TimeOfAppointment : DateTime.Parse($"{GetDFormat(date.Date)} {date.TimeOfPickup}").AddSeconds(duration1).AddMinutes(30).ToShortTimeString();
                                        dateTime = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j - 1].Date)} {date1}");
                                    }
                                    if (onePointForAddressOrders[j].Type == "Start")
                                    {
                                        dateTime1 = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j].Date)} {onePointForAddressOrders[j].PTime}");
                                    }
                                    else if (onePointForAddressOrders[j].Type == "End")
                                    {
                                        var    date  = orders.Find(o => o.ID == onePointForAddressOrders[j].IDorder);
                                        string date1 = date.TimeOfAppointment != null ? date.TimeOfAppointment : DateTime.Parse($"{GetDFormat(date.Date)} {date.TimeOfPickup}").AddMinutes(90).ToShortTimeString();
                                        dateTime1 = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j].Date)} {date1}");
                                        onePointForAddressOrders[j].PTime = date1;
                                    }
                                    if (onePointForAddressOrders[j].Type == "Start" &&
                                        !(dateTime.AddSeconds(duration1) < dateTime1.AddMinutes(20) &&
                                          dateTime1.AddMinutes(-20) < dateTime.AddSeconds(duration1)))
                                    {
                                        isAddOrder = false;
                                        break;
                                    }
                                    else if (onePointForAddressOrders[j].Type == "End" &&
                                             !(dateTime.AddSeconds(duration1) < dateTime1))
                                    {
                                        isAddOrder = false;
                                        break;
                                    }
                                }
                                if (isAddOrder)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                    if (isAddOrder)
                    {
                        Order order1 = orders.Find(o => o.ID.ToString() == locationsOrder[i].ID);
                        if (order1.CountCustomer <= numberOfSeats)
                        {
                            orderMobile.OnePointForAddressOrders.Insert(positionS, new OnePointForAddressOrder(order1.ID, locationsOrder[i].lat, locationsOrder[i].lng, order1.TimeOfPickup, order1.Date, "Start", order1.FromAddress));
                            if (isOnTheWay)
                            {
                                orderMobile.OnePointForAddressOrders.Add(new OnePointForAddressOrder(order1.ID, locationsOrder[i].latE, locationsOrder[i].lngE, order1.TimeOfAppointment, order1.Date, "End", order1.ToAddress));
                            }
                            else
                            {
                                orderMobile.OnePointForAddressOrders.Insert(positionE, new OnePointForAddressOrder(order1.ID, locationsOrder[i].latE, locationsOrder[i].lngE, order1.TimeOfAppointment, order1.Date, "End", order1.ToAddress));
                            }
                            orderMobile.Orders.Add(order1);
                            locationsOrder.Remove(locationsOrder.Find(l => l.ID == order1.ID.ToString()));
                            numberOfSeats -= order1.CountCustomer;
                        }
                    }
                }
                await sqlCoommandTaxiApi.SetOrederMobile(orderMobile, locationsAcceptOrder[0].ID, isNew);

                ManagerNotifyMobileApi managerNotifyMobileApi = new ManagerNotifyMobileApi();
                string tokenShope = sqlCoommandTaxiApi.GetTokenShope(orderMobile.IdDriver);
                if (isNew)
                {
                    managerNotifyMobileApi.SendNotyfyStatusPickup(tokenShope, "Order", "New order for you", "System gave you a new order, The system gave you a new order, accept the order if possible, if you have no orders, accept the order within 5 minutes");
                }
                else
                {
                    managerNotifyMobileApi.SendNotyfyStatusPickup(tokenShope, "Order", "Next order for you", "your next order is created, it will be available after the completion of the current order");
                }
            }
        }
Пример #22
0
        public List <Order> GetOrdersSuitableAndInsert(string idDriver, OrderMobile orderMobile, Order order1)
        {
            OrderMobileWorke orderMobileWorke = new OrderMobileWorke();

            return(orderMobileWorke.SuitableOrders(idDriver, orderMobile, order1));
        }
Пример #23
0
        private List <Order> OrderOnTheWay(List <Model.Location> locationsOrder, Model.Location locationDriver, OrderMobile orderMobile, List <Order> orders, int numberOfSeats)
        {
            List <Order> orders1 = new List <Order>();
            List <Steps> steps   = new List <Steps>();

            for (int i = 1; i < orderMobile.OnePointForAddressOrders.Count; i++)
            {
                steps.AddRange(connectorApiMaps.GetGetDirections($"{ConvertTOString(orderMobile.OnePointForAddressOrders[i-1].Lat)},{ConvertTOString(orderMobile.OnePointForAddressOrders[i - 1].Lng)}", $"{ConvertTOString(orderMobile.OnePointForAddressOrders[i].Lat)},{ConvertTOString(orderMobile.OnePointForAddressOrders[i].Lng)}"));
            }
            for (int i = 0; i < locationsOrder.Count; i++)
            {
                if (locationsOrder[i].CountCusstomer > numberOfSeats)
                {
                    continue;
                }
                bool   isAddOrder      = true;
                bool   isOnTheWay      = false;
                int    positionS       = 0;
                int    positionE       = 0;
                bool   isOnTheWayStart = false;
                double lat             = 0;
                double lng             = 0;
                double latF            = locationsOrder[i].lat;
                double lngF            = locationsOrder[i].lng;
                foreach (Steps step in steps)
                {
                    List <OnePointForAddressOrder> onePointForAddressOrders = new List <OnePointForAddressOrder>();
                    onePointForAddressOrders.AddRange(orderMobile.OnePointForAddressOrders);
                    double tmpLoc = Convert.ToDouble(step.end_location.lat - step.start_location.lat);
                    lat    = step.start_location.lat + tmpLoc;
                    tmpLoc = step.end_location.lng - step.start_location.lng;
                    lng    = step.start_location.lng + tmpLoc;
                    lng    = step.start_location.lng + tmpLoc;
                    if ((latF - 0.013 < lat && lat + 0.013 > latF) &&
                        (lngF - 0.013 < lng && lng + 0.013 > lngF) && !isOnTheWayStart)
                    {
                        Model.Location locationNewS = new Model.Location(locationsOrder[i].lat, locationsOrder[i].lng);
                        Model.Location locationNewE = new Model.Location(locationsOrder[i].latE, locationsOrder[i].lngE);
                        GetPositionLocation(onePointForAddressOrders, locationNewS, locationDriver, ref positionS);
                        Order order1 = orders.Find(o => o.ID.ToString() == locationsOrder[i].ID);
                        onePointForAddressOrders.Insert(positionS, new OnePointForAddressOrder(order1.ID, locationsOrder[i].lat, locationsOrder[i].lng, order1.TimeOfPickup, order1.Date, "Start", order1.FromAddress));
                        if (GetEndOrderOnTheWay(steps.GetRange(steps.IndexOf(step), (steps.Count - 1) - steps.IndexOf(step)), locationsOrder[i]))
                        {
                            GetPositionLocation(onePointForAddressOrders, locationNewE, locationDriver, ref positionE);
                            onePointForAddressOrders.Insert(positionE, new OnePointForAddressOrder(order1.ID, locationsOrder[i].latE, locationsOrder[i].lngE, order1.TimeOfAppointment, order1.Date, "End", order1.ToAddress));
                        }
                        else
                        {
                            onePointForAddressOrders.Add(new OnePointForAddressOrder(order1.ID, locationsOrder[i].latE, locationsOrder[i].lngE, order1.TimeOfAppointment, order1.Date, "End", order1.ToAddress));
                            isOnTheWay = true;
                        }
                        for (int j = 1; j < onePointForAddressOrders.Count; j++)
                        {
                            DateTime dateTime  = new DateTime();
                            DateTime dateTime1 = new DateTime();
                            int      duration1 = connectorApiMaps.GetGetDuration($"{ConvertTOString(onePointForAddressOrders[j - 1].Lat)},{ConvertTOString(onePointForAddressOrders[j - 1].Lng)}", $"{ConvertTOString(onePointForAddressOrders[j].Lat)},{ConvertTOString(onePointForAddressOrders[j].Lng)}");
                            if (duration1 < 60 * 10)
                            {
                                continue;
                            }
                            if (onePointForAddressOrders[j - 1].Type == "Start")
                            {
                                dateTime = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j - 1].Date)} {onePointForAddressOrders[j - 1].PTime}");
                            }
                            else if (onePointForAddressOrders[j - 1].Type == "End")
                            {
                                var    date  = orders.Find(o => o.ID == onePointForAddressOrders[j - 1].IDorder);
                                string date1 = date.TimeOfAppointment != null ? date.TimeOfAppointment : DateTime.Parse($"{GetDFormat(date.Date)} {date.TimeOfPickup}").AddSeconds(duration1).AddMinutes(30).ToShortTimeString();
                                dateTime = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j - 1].Date)} {date1}");
                            }
                            if (onePointForAddressOrders[j].Type == "Start")
                            {
                                dateTime1 = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j].Date)} {onePointForAddressOrders[j].PTime}");
                            }
                            else if (onePointForAddressOrders[j].Type == "End")
                            {
                                var    date  = orders.Find(o => o.ID == onePointForAddressOrders[j].IDorder);
                                string date1 = date.TimeOfAppointment != null ? date.TimeOfAppointment : DateTime.Parse($"{GetDFormat(date.Date)} {date.TimeOfPickup}").AddMinutes(90).ToShortTimeString();
                                dateTime1 = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j].Date)} {date1}");
                                onePointForAddressOrders[j].PTime = date1;
                            }
                            if (onePointForAddressOrders[j].Type == "Start" &&
                                !(dateTime.AddSeconds(duration1) < dateTime1.AddMinutes(10) &&
                                  dateTime1.AddMinutes(-10) < dateTime.AddSeconds(duration1)))
                            {
                                isAddOrder = false;
                                break;
                            }
                            else if (onePointForAddressOrders[j].Type == "End" &&
                                     !(dateTime.AddSeconds(duration1) < dateTime1))
                            {
                                isAddOrder = false;
                                break;
                            }
                        }
                        if (isAddOrder)
                        {
                            break;
                        }
                    }
                }
                if (isAddOrder)
                {
                    Order order1 = orders.Find(o => o.ID.ToString() == locationsOrder[i].ID);
                    if (order1.CountCustomer <= numberOfSeats)
                    {
                        orders1.Add(order1);
                        numberOfSeats -= order1.CountCustomer;
                        orders.Remove(order1);
                    }
                }
            }
            return(orders1);
        }
 private void OrderMobile_Click(object sender, EventArgs e)
 {
     OrderMobile.Clear();
 }