public async Task SendStatusUpdateEmailToAdminAsync(string statusString, Delivery delivery, List <EmployeeUser> employees) { foreach (EmployeeUser user in employees) { string emailMessage = "Hi " + user.NormalizedUserName; emailMessage += "The status of delivery for the address " + DirectionsService.getStringFromAddress(delivery.Client.Address) + " dated " + delivery.DeliverBy.ToString() + " has been changed to " + statusString; string emailAddress = user.Email; string emailSubject = "Delivery status change to: " + statusString; await emailSender.SendEmailAsync(emailAddress, emailSubject, emailMessage); } }
public async Task SendStatusUpdateEmailToClientAsync(Status status, Delivery delivery, Client client) { string emailMessage = "Hi " + client.FirstName; if (!status.Equals(Status.FailedDelivery)) { emailMessage += "The status of delivery for the address " + DirectionsService.getStringFromAddress(delivery.Client.Address) + " dated " + delivery.DeliverBy.ToString() + " has been changed to " + status.DisplayName(); string emailAddress = client.Email; string emailSubject = "The status of your order has changed to: " + status.DisplayName(); await emailSender.SendEmailAsync(emailAddress, emailSubject, emailMessage); } }
public virtual async Task addLocationDataToAddress(Address address) { string addressString = DirectionsService.getStringFromAddress(address); string uri = "https://maps.googleapis.com/maps/api/geocode/json?address=" + addressString; HttpResponseMessage response = await googleMaps.performGoogleMapsRequestAsync(uri); var jsonString = response.Content.ReadAsStringAsync().Result; JObject json = JObject.Parse(jsonString); var latValue = (string)json.SelectToken("results[0].geometry.location.lat"); var lat = Convert.ToDouble(latValue); var lngValue = (string)json.SelectToken("results[0].geometry.location.lng"); var lng = Convert.ToDouble(lngValue); address.Lat = lat; address.Lng = lng; }
public virtual async Task <PickUpAddress> FindClosestDepotLocationForRoute(ICollection <PickUpAddress> pickUpLocations, Center center) { var distances = new double[pickUpLocations.Count()]; for (int i = 0; i < pickUpLocations.Count(); i++) { string addressString = DirectionsService.getStringFromAddress(pickUpLocations.ElementAt(i)); string uri = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=" + center.lat + "," + center.lng + "&destinations=" + addressString; HttpResponseMessage response = await googleMaps.performGoogleMapsRequestAsync(uri); var jsonString = response.Content.ReadAsStringAsync().Result; JObject json = JObject.Parse(jsonString); var distance = Convert.ToDouble((string)json.SelectToken("rows[0].elements[0].distance.value")); distances[i] = distance; } var minDistanceIndex = distances.ToList().IndexOf(distances.Min()); return(pickUpLocations.ElementAt(minDistanceIndex)); }
public virtual async Task <double> getDistanceBetweenTwoAddresses(Address addressOne, Address addressTwo) { string addressOneString = DirectionsService.getStringFromAddress(addressOne); string addressTwoString = DirectionsService.getStringFromAddress(addressTwo); string uri = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=" + addressOneString + "&destinations=" + addressTwoString; HttpResponseMessage response = await googleMaps.performGoogleMapsRequestAsync(uri); var jsonString = response.Content.ReadAsStringAsync().Result; JObject json = JObject.Parse(jsonString); var distanceValue = (string)json.SelectToken("rows[0].elements[0].distance.text"); if (distanceValue == null) // can be NOT FOUND status { return(1000); } var valueInDouble = Convert.ToDouble(distanceValue.Replace("mi", "")); return(valueInDouble); }
private async Task SelectDeliveriesBasedOnDistance(double DistanceWithin, IEnumerable <Address> addresses, HttpClient httpClient, string currentLocationString, IList <Delivery> deliveries) { foreach (Address address in addresses) { string addressLocationString = DirectionsService.getStringFromAddress(address, true); HttpResponseMessage response = await googleMaps.createDistanceUriAndGetResponse(currentLocationString, addressLocationString, httpClient); if (response.IsSuccessStatusCode) { double distanceToAddress = GetDistanceFromResponse(response); if (distanceToAddress != DEFAULT_NON_FOUND_ADDRESS_VALUE && distanceToAddress < DistanceWithin) { Delivery delivery = null; Type type = address.GetType(); if (type == typeof(PickUpAddress)) { delivery = context.Deliveries .Include(d => d.DeliveryStatus) .SingleOrDefault(); } else { delivery = context.Deliveries .Include(d => d.DeliveryStatus) .Include(d => d.Client) .Include(d => d.Client.Address) .Where(d => d.Client.Address.ID == address.ID) .FirstOrDefault(); } if (delivery != null) { DeliveryStatus status = delivery.DeliveryStatus; if (status != null && status.Status == Status.New) { deliveries.Add(delivery); } } } } } }