コード例 #1
0
ファイル: PersonRepository.cs プロジェクト: Maxusbr/GT_Admin
        /// <see cref="IPersonRepository.UpdatePlace" />
        public int UpdatePlace(string country, string place, string abr)
        {
            var cnt = db.Country.FirstOrDefault(o => o.Name.ToLower().Equals(country));

            if (cnt == null)
            {
                cnt = db.Country.Add(new Country {
                    Name = country
                });
                db.SaveChanges();
            }
            var model = new CountryPlace {
                Name = place, Abr = abr, CountryId = cnt.Id
            };
            var pls = db.CountryPlaces.FirstOrDefault(o => o.Name.ToLower().Equals(place));

            if (pls != null)
            {
                db.Entry(pls).CurrentValues.SetValues(model);
            }
            else
            {
                pls = db.CountryPlaces.Add(model);
            }
            db.SaveChanges();
            return(pls.Id);
        }
コード例 #2
0
 public static CountryPlaceModel GetCountryPlaceModel(CountryPlace model)
 {
     return(model != null ? new CountryPlaceModel
     {
         Id = model.Id,
         Name = model.Name,
         IdCountry = model.Region.Country_Id,
         CountryName = model.Region.Country.Name
     } : null);
 }
コード例 #3
0
        public CountryPlace AddPlace(CountryTemp c, Country country, CountryPlaceType cp)
        {
            bool isFailed;

            if (IsStringNullOrWhite(c.Place))
            {
                return(null);
            }
            if (!IsPlaceExist(c))
            {
                var o = new CountryPlace();
                o.Name      = c.Place;
                o.XLating   = c.XLating;
                o.YLating   = c.YLating;
                o.WikiLink  = c.WikiLink;
                o.CountryID = country.CountryID;
                o.Area      = c.Area;
                if (cp != null)
                {
                    o.CountryPlaceTypeID = cp.CountryPlaceTypeID;
                }
                db.CountryPlaces.Add(o);
                var failed = db.SaveChanges(o, "AddPlace");
                //var failed = db.SaveChanges();
                isFailed = (failed == -1) ? true : false;
                if (isFailed)
                {
                    AddError(c, "AddPlace");
                }
                return(o);
            }
            else
            {
                var x = GetPlace(c, country);
                if (x == null)
                {
                    isFailed = true;
                    AddError(c, "Place");
                }
                return(x);
            }
        }
コード例 #4
0
 public void AddRelPlaceAlternatives(CountryTemp p1, CountryPlace p2, ref bool isFailed)
 {
     isFailed = false;
     if (p1.AlterNativePlaceNames != null)
     {
         foreach (var item in p1.AlterNativePlaceNames)
         {
             var o = new CountryPlaceAlternative();
             o.AlternativeName = item;
             o.CountryPlaceID  = p2.CountryPlaceID;
             var failed = db.SaveChanges(o, "AddRelPlaceAlternatives");
             //var failed = db.SaveChanges();
             isFailed = (failed == -1) ? true : false;
             if (isFailed)
             {
                 AddError(p1, "Add Alter Place name :" + item);
             }
         }
     }
 }
コード例 #5
0
ファイル: PersonRepository.cs プロジェクト: Maxusbr/GT_Admin
 /// <see cref="IPersonRepository.SaveCountryPlace" />
 public CountryPlace SaveCountryPlace(CountryPlace place)
 {
     if (place.Id == 0)
     {
         db.Entry(place).State = System.Data.Entity.EntityState.Added;
     }
     else if (place.Id > 0)
     {
         var pls = db.CountryPlaces.FirstOrDefault(o => o.Name.ToLower().Equals(place.Name));
         if (pls != null)
         {
             db.Entry(pls).CurrentValues.SetValues(place);
         }
     }
     try
     {
         db.SaveChanges();
     }
     catch (Exception e)
     {
         return(null);
     }
     return(place);
 }