public DistributionCenter GetNearest(Address address) {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            DistributionCenter distcenter = new DistributionCenter();
            try {
                double earth = 3963.1676; // radius of Earth in miles
                DCList d = (from dc in db.DistributionCenters
                            where dc.State1.countryID == address.State1.countryID
                            select new DCList {
                                ID = dc.ID,
                                distance = earth * (
                                                    2 * Math.Atan2(
                                                        Math.Sqrt((Math.Sin((Convert.ToDouble(dc.Latitude - address.latitude) * (Math.PI / 180)) / 2) * Math.Sin((Convert.ToDouble(dc.Latitude - address.latitude) * (Math.PI / 180)) / 2)) + ((Math.Sin((Convert.ToDouble(dc.Longitude - address.longitude) * (Math.PI / 180)) / 2)) * (Math.Sin((Convert.ToDouble(dc.Longitude - address.longitude) * (Math.PI / 180)) / 2))) * Math.Cos(Convert.ToDouble(address.latitude) * (Math.PI / 180)) * Math.Cos(Convert.ToDouble(dc.Latitude) * (Math.PI / 180))),
                                                        Math.Sqrt(1 - ((Math.Sin((Convert.ToDouble(dc.Latitude - address.latitude) * (Math.PI / 180)) / 2) * Math.Sin((Convert.ToDouble(dc.Latitude - address.latitude) * (Math.PI / 180)) / 2)) + ((Math.Sin((Convert.ToDouble(dc.Longitude - address.longitude) * (Math.PI / 180)) / 2)) * (Math.Sin((Convert.ToDouble(dc.Longitude - address.longitude) * (Math.PI / 180)) / 2))) * Math.Cos(Convert.ToDouble(address.latitude) * (Math.PI / 180)) * Math.Cos(Convert.ToDouble(dc.Latitude) * (Math.PI / 180))))
                                                    )
                                                )
                            }).OrderBy(x => x.distance).First<DCList>();

                distcenter = db.DistributionCenters.Where(x => x.ID == d.ID).First<DistributionCenter>();
            } catch {
                DCList d = (from dc in db.DistributionCenters
                            where dc.State1.countryID == address.State1.countryID
                            select new DCList {
                                ID = dc.ID,
                                distance = 0
                            }).OrderBy(x => x.distance).First<DCList>();
                distcenter = db.DistributionCenters.Where(x => x.ID == d.ID).First<DistributionCenter>();
            };
            return distcenter;
        }
		private void detach_DistributionCenters(DistributionCenter entity)
		{
			this.SendPropertyChanging();
			entity.State1 = null;
		}
 partial void DeleteDistributionCenter(DistributionCenter instance);
 partial void UpdateDistributionCenter(DistributionCenter instance);
 partial void InsertDistributionCenter(DistributionCenter instance);
Exemple #6
0
        public ShippingResponse getShipping()
        {
            Settings settings = new Settings();
            FedExAuthentication auth = new FedExAuthentication {
                AccountNumber = Convert.ToInt32(settings.Get("FedExAccount")),
                Key = settings.Get("FedExKey"),
                Password = settings.Get("FedExPassword"),
                CustomerTransactionId = "",
                MeterNumber = Convert.ToInt32(settings.Get("FedExMeter"))
            };

            ShippingAddress destination = new ShippingAddress();
            destination = this.Shipping.getShipping();
            DistributionCenter d = new DistributionCenter().GetNearest(this.Shipping.GeoLocate());
            ShippingAddress origin = d.getAddress().getShipping();
            List<int> parts = new List<int>();
            foreach (CartItem item in this.CartItems) {
                for (int i = 1; i <= item.quantity; i++) {
                    parts.Add(item.partID);
                }
            }

            ShippingResponse response = CURTAPI.GetShipping(auth, origin, destination, parts);

            return response;
        }