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); } }
public CountryPlaceType AddPlaceType(CountryTemp c) { bool isFailed; if (IsStringNullOrWhite(c.PlaceType)) { return(null); } if (!IsPlaceTypeExist(c.PlaceType)) { if (!string.IsNullOrWhiteSpace(c.PlaceType.Trim())) { var o = new CountryPlaceType(); o.PlaceType = c.PlaceType; db.CountryPlaceTypes.Add(o); var failed = db.SaveChanges(o, "AddPlaceType"); //var failed = db.SaveChanges(); isFailed = (failed == -1) ? true : false; if (isFailed) { AddError(c, "AddPlaceType"); } return(o); } return(null); } else { var x = db.CountryPlaceTypes.FirstOrDefault(n => n.PlaceType == c.PlaceType); if (x == null) { isFailed = true; AddError(c, "PlaceType"); } return(x); } }