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; }
internal bool Equals(Address address) { bool isequal = false; isequal = ( this.first.ToLower().Trim() == address.first.ToLower().Trim() && this.last.ToLower().Trim() == address.last.ToLower().Trim() && this.street1.ToLower().Trim() == address.street1.ToLower().Trim() && this.street2.ToLower().Trim() == address.street2.ToLower().Trim() && this.city.ToLower().Trim() == address.city.ToLower().Trim() && this.state == address.state && this.postal_code.ToLower().Trim() == address.postal_code.ToLower().Trim()) && this.residential == address.residential; return isequal; }
public Address getAddress() { Address address = new Address { first = this.Name, street1 = this.Street1, street2 = this.Street2, city = this.City, state = this.State, State1 = this.State1, postal_code = this.PostalCode, residential = false, latitude = this.Latitude, longitude = this.Longitude }; return address; }
internal void GetShipping() { Address shipping = new Address(); try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); shipping = db.Addresses.Where(x => x.ID.Equals(this.ship_to)).FirstOrDefault<Address>(); } catch (Exception) { } this.Shipping = shipping; }
internal void GetBilling() { Address billing = new Address(); try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); billing = db.Addresses.Where(x => x.ID.Equals(this.bill_to)).FirstOrDefault<Address>(); } catch (Exception) { } this.Billing = billing; }
private void detach_Addresses(Address entity) { this.SendPropertyChanging(); entity.State1 = null; }
private void attach_Addresses(Address entity) { this.SendPropertyChanging(); entity.State1 = this; }
partial void DeleteAddress(Address instance);
partial void UpdateAddress(Address instance);
partial void InsertAddress(Address instance);
internal void UpdateAddress(int ID, string first,string last, string street1, string street2, string city, int state_id, string zip, bool residential) { Address tmp = new Address(); EcommercePlatformDataContext db = new EcommercePlatformDataContext(); tmp = db.Addresses.Where(x => x.ID.Equals(ID)).FirstOrDefault<Address>(); tmp.Update(first, last, street1, street2, city, state_id, zip, residential); }
internal void SaveAddresses(Address billing, Address shipping) { this.billingID = billing.ID; this.shippingID = shipping.ID; Customer tmp = new Customer(); EcommercePlatformDataContext db = new EcommercePlatformDataContext(); tmp = db.Customers.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<Customer>(); tmp.billingID = this.billingID; tmp.shippingID = this.shippingID; db.SubmitChanges(); }