public bool AddAddress(string Address1, string PostCode, int? CountryID, string Town, string County ) { try { var addr = new Address(); // check town exits, if not add town if (Town != "") { var lsTown = _db.Towns.Where(m => m.TownName == Town && m.CountryID == CountryID); if (lsTown.Count() != 0) { addr.TownID = lsTown.First().TownID; } else { var town = new Town(); town.TownName = Town; town.CountryID = CountryID; var re = CreateTown(town); if (re == false) return false; addr.TownID = town.TownID; } } // check county exits, if not add county if (County != "") { var lsCounty = _db.Counties.Where(m => m.CountyName == County && m.CountryID == CountryID); if (lsCounty.Count() != 0) { addr.CountyID = lsCounty.First().CountyID; } else { var county = new County(); county.CountyName = County; county.CountryID = CountryID; var re = CreateCounty(county); if (re == false) return false; addr.CountyID = county.CountyID; } } addr.CountryID = CountryID; addr.PostCode = PostCode; addr.Address1 = Address1; CreateAddress(addr); return true; } catch { return false; } }
public bool CreateAddress(Address addr) { try { _db.Addresses.InsertOnSubmit(addr); _db.SubmitChanges(); return true; } catch { return false; } }
partial void DeleteAddress(Address instance);
partial void UpdateAddress(Address instance);
partial void InsertAddress(Address instance);
private void detach_Addresses(Address entity) { this.SendPropertyChanging(); entity.Country = null; }
private void attach_Addresses(Address entity) { this.SendPropertyChanging(); entity.Country = this; }