コード例 #1
0
        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;
            }
        }
コード例 #2
0
		private void detach_Towns(Town entity)
		{
			this.SendPropertyChanging();
			entity.Country = null;
		}
コード例 #3
0
		private void attach_Towns(Town entity)
		{
			this.SendPropertyChanging();
			entity.Country = this;
		}
コード例 #4
0
 partial void DeleteTown(Town instance);
コード例 #5
0
 partial void UpdateTown(Town instance);
コード例 #6
0
 partial void InsertTown(Town instance);
コード例 #7
0
 public bool CreateTown(Town town)
 {
     try
     {
         _db.Towns.InsertOnSubmit(town);
         _db.SubmitChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }