public CountryDistrict AddDistrict(CountryTemp c, Country country)
        {
            bool isFailed;

            if (IsStringNullOrWhite(c.District))
            {
                return(null);
            }
            if (c.IsStateOrDistrict)
            {
                if (!IsDistrictExist(c.District))
                {
                    var district = new CountryDistrict();

                    district.DistrictName      = c.District;
                    district.CountryID         = country.CountryID;
                    district.IsCounty          = c.IsCounty;
                    district.IsConfirmDistrict = c.IsConfirmDistrict;
                    db.CountryDistricts.Add(district);
                    var failed = db.SaveChanges(district, "AddDistrict");
                    //var failed = db.SaveChanges();
                    isFailed = (failed == -1) ? true : false;
                    if (isFailed)
                    {
                        AddError(c, "District");
                    }
                    return(district);
                }
                else
                {
                    var x = db.CountryDistricts.FirstOrDefault(n => n.DistrictName == c.District);
                    if (x == null)
                    {
                        isFailed = true;
                        AddError(c, "District");
                    }
                    return(x);
                }
            }

            return(null);
        }
 public bool IsStateDistrictExist(CountrySate s, CountryDistrict d)
 {
     return(db.CountryStateDistrictRelations.Any(n => n.CountrySateID == s.CountrySateID && n.CountryDistrictID == d.CountryDistrictID));
 }
        public CountryStateDistrictRelation AddRelStateDistrict(CountryTemp c, CountrySate p1, CountryDistrict p2)
        {
            bool isFailed;

            if (p1 != null)
            {
                if (!IsStateDistrictExist(p1, p2))
                {
                    var o = new CountryStateDistrictRelation();

                    o.CountrySateID     = p1.CountrySateID;
                    o.CountryDistrictID = p2.CountryDistrictID;


                    db.CountryStateDistrictRelations.Add(o);
                    var failed = db.SaveChanges(o, "AddRelStateDistrict");
                    //var failed = db.SaveChanges();
                    isFailed = (failed == -1) ? true : false;
                    if (!isFailed)
                    {
                        return(o);
                    }
                    else
                    {
                        AddError(c, "StateDistrictRel");
                        return(null);
                    }
                }
            }
            return(null);
        }