public JsonResult DeliverWithinDays(string days) { var deliveries = DateFilter.getDeliveriesWithinDays(company.Deliveries.ToList(), Convert.ToInt32(days)); var routes = DateFilter.getRoutesWithinDays(company.Routes.ToList(), Convert.ToInt32(days)); Response.StatusCode = (int)HttpStatusCode.OK; List <ShipperSingleDeliveryMapViewModel> delsWithAddress = new List <ShipperSingleDeliveryMapViewModel>(); foreach (Delivery delivery in deliveries) { ShipperSingleDeliveryMapViewModel model = new ShipperSingleDeliveryMapViewModel(); model.Client = delivery.Client; model.addressString = DirectionsService.getStringFromAddress(delivery.Client.Address); model.ID = delivery.ID; string clientName = delivery.Client.FirstName + " " + delivery.Client.LastName; string currentStatus = StatusExtension.DisplayName(delivery.DeliveryStatus.Status); string deliverByDate = delivery.DeliverBy.Value.Date.ToString(); string deliverByString = deliverByDate.Substring(0, deliverByDate.IndexOf(" ")); model.clientName = clientName; model.currentStatus = currentStatus; model.deliverBy = deliverByString; delsWithAddress.Add(model); } MapObjects result = new MapObjects(deliveries, routes, delsWithAddress, company); return(Json(result)); }
public IActionResult RouteDeliveries(int?id) { Route route = driver.Routes.Where(r => r.ID == id).FirstOrDefault(); List <Delivery> deliveries = route.Deliveries.ToList(); List <DriverDeliveryViewModel> modelsList = new List <DriverDeliveryViewModel>(); foreach (Delivery delivery in deliveries) { DriverDeliveryViewModel model = new DriverDeliveryViewModel(); model.ClientName = delivery.Client.FirstName + " " + delivery.Client.LastName; model.DeliverBy = delivery.DeliverBy; string deliverytatusString = StatusExtension.DisplayName(delivery.DeliveryStatus.Status); if (delivery.DeliveryStatus.Status.Equals(Status.Delivered)) { DateTime deliveredDate = delivery.DeliveryStatus.DeliveredDate.Value; deliverytatusString += " " + deliveredDate.ToString("MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture); } else if (delivery.DeliveryStatus.Status.Equals(Status.FailedDelivery)) { deliverytatusString = "Failed, reason: " + delivery.DeliveryStatus.ReasonFailed; } model.DeliveryStatusString = deliverytatusString; model.ID = delivery.ID; model.ItemSizeString = ItemSizeDimensionsExtension.getItemDimensionsBasedOnSize(delivery.ItemSize).ToString(); model.ItemWeight = delivery.ItemWeight; model.ClientAddress = delivery.Client.Address; modelsList.Add(model); } return(View(modelsList)); }
public IActionResult Index() { var deliveries = DateFilter.getDeliveriesWithinDays(company.Deliveries.ToList(), 2); var depots = company.PickUpLocations.ToList(); List <ShipperSingleDeliveryMapViewModel> delsWithAddress = new List <ShipperSingleDeliveryMapViewModel>(); foreach (Delivery delivery in deliveries) { ShipperSingleDeliveryMapViewModel model = new ShipperSingleDeliveryMapViewModel(); model.Client = delivery.Client; model.addressString = DirectionsService.getStringFromAddress(delivery.Client.Address); model.ID = delivery.ID; string clientName = delivery.Client.FirstName + " " + delivery.Client.LastName; string currentStatus = StatusExtension.DisplayName(delivery.DeliveryStatus.Status); string deliverByDate = delivery.DeliverBy.Value.Date.ToString(); string deliverByString = deliverByDate.Substring(0, deliverByDate.IndexOf(" ")); model.clientName = clientName; model.currentStatus = currentStatus; model.deliverBy = deliverByString; delsWithAddress.Add(model); } MapObjects objects = new MapObjects(deliveries, depots, company.Routes.ToList(), delsWithAddress, company); return(View(objects)); }
public IActionResult MapDelivery(int?id) { var delivery = _context.Deliveries .Include(d => d.Client) .Include(d => d.Client.Address) .Include(d => d.DeliveryStatus) .SingleOrDefault(d => d.ID == id); double locationLat = delivery.Client.Address.Lat; double locationLng = delivery.Client.Address.Lng; string clientName = delivery.Client.FirstName + " " + delivery.Client.LastName; string deliverytatusString = StatusExtension.DisplayName(delivery.DeliveryStatus.Status); if (delivery.DeliveryStatus.Status.Equals(Status.Delivered)) { DateTime deliveredDate = delivery.DeliveryStatus.DeliveredDate.Value; deliverytatusString += " " + deliveredDate.ToString("MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture); } string addressString = DirectionsService.getStringFromAddress(delivery.Client.Address); string deliverByDate = delivery.DeliverBy.Value.Date.ToString(); string deliverByString = deliverByDate.Substring(0, deliverByDate.IndexOf(" ")); DriverSingleDeliveryMapView model = new DriverSingleDeliveryMapView(locationLat, locationLng, clientName, deliverByString, deliverytatusString, addressString); return(View(model)); }
public JsonResult UpdateStatus([FromBody] StatusUpdateRequest updateRequest) { Status updateStatus = StatusExtension.statusFromString(updateRequest.status); Delivery delivery = _context.Deliveries .Include(d => d.DeliveryStatus) .SingleOrDefault(d => d.ID == updateRequest.id); if (delivery == null) { Response.StatusCode = 400; return(Json(HttpStatusCode.BadRequest)); } bool statusUpdated = statusUpdateService.UpdateDeliveryStatus(delivery, updateStatus); if (!statusUpdated) { Response.StatusCode = 400; return(Json(HttpStatusCode.BadRequest)); } delivery.DeliveryStatus.Status = updateStatus; string updateStatusString = StatusExtension.DisplayName(delivery.DeliveryStatus.Status); if (updateStatus.Equals(Status.Delivered)) { DateTime deliveredDate = DateTime.Now; delivery.DeliveryStatus.DeliveredDate = deliveredDate; updateStatusString += " " + deliveredDate.ToString("MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture); } Company company = _context.Companies.Include(c => c.Team.Employees).Where(c => c.ID == driver.User.CompanyID).SingleOrDefault(); notificationService.SendStatusUpdateEmailToAdminAsync(updateStatusString, delivery, company.Team.Employees.ToList()); if (updateStatus.Equals(Status.InTransit)) { notificationService.SendStatusUpdateEmailToClientAsync(updateStatus, delivery, delivery.Client); } Response.StatusCode = 200; _context.SaveChanges(); return(Json(updateStatusString)); }