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(); }
public async Task ReCurentStatus(string idShip, string status) { sqlCommandApiMobile.ReCurentStatus(idShip, status); await Task.Run(() => { try { string tokenShope = sqlCommandApiMobile.GerShopTokenForShipping(idShip); ManagerNotifyMobileApi managerNotifyMobileApi = new ManagerNotifyMobileApi(); if (status == "Picked up") { managerNotifyMobileApi.SendNotyfyStatusPickup(idShip, tokenShope); } else if (status == "Delivered,Paid") { managerNotifyMobileApi.SendNotyfyStatusDelyvery(idShip, tokenShope, "Cars passed inspection, the order is paid"); } else if (status == "Delivered,Billed") { managerNotifyMobileApi.SendNotyfyStatusDelyvery(idShip, tokenShope, "Cars passed inspection, waiting for payment (Billing)"); } } catch (Exception e) { File.WriteAllText("ReCurentStatus1.txt", e.Message); } }); }
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"); }
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(); }
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(); }
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"); } } }