public static string AddCity(string CityName)
        {
            // result 0 for not saved
            // result -1 for some internal error
            // result 1 or greater than 1 for successfuly saved
            string     result = "0";
            CityDetail city   = new CityDetail();

            try
            {
                var IsCityExsist = Global.dc.CityDetails.FirstOrDefault(i => i.IsActive == true && (!i.IsDeleted.Value || !i.IsDeleted.HasValue) && i.CityName.ToLower() == CityName.ToLower());
                if (IsCityExsist != null)
                {
                    result = "2";
                }
                else
                {
                    city.CityName  = CityName;
                    city.IsActive  = true;
                    city.IsDeleted = false;

                    Global.dc.CityDetails.Add(city);

                    int count = Global.dc.SaveChanges();
                    result = Convert.ToString(count);
                }
            }
            catch (Exception)
            {
                result = "-1";
            }
            return(result);
        }
Exemplo n.º 2
0
        public string DeleteCity(string ID)
        {
            string result = string.Empty;

            try
            {
                int        CityID = Convert.ToInt32(ID);
                AreaDetail area   = Global.dc.AreaDetails.FirstOrDefault(i => i.CityID == CityID && i.IsActive == true && (!i.IsDeleted.Value || !i.IsDeleted.HasValue));
                if (area != null)
                {
                    //City Is used in another
                    result = "4";
                }
                else
                {
                    CityDetail city = Global.dc.CityDetails.FirstOrDefault(i => i.ID == CityID && i.IsActive == true && (!i.IsDeleted.Value || !i.IsDeleted.HasValue));
                    if (city != null)
                    {
                        city.IsDeleted = true;
                        int count = Global.dc.SaveChanges();
                        result = Convert.ToString(count);
                    }
                    else
                    {
                        result = "3";
                    }
                }
            }
            catch (Exception)
            {
                result = "-1";
            }
            return(result);
        }
Exemplo n.º 3
0
        public string EditCity(string ID)
        {
            string result = string.Empty;

            try
            {
                int        CityID = Convert.ToInt32(ID);
                CityDetail city   = Global.dc.CityDetails.FirstOrDefault(i => i.ID == CityID && i.IsActive == true && (!i.IsDeleted.Value || !i.IsDeleted.HasValue));
                if (city != null)
                {
                    result = city.CityName;
                }
                else
                {
                    result = "3";
                }
            }

            catch (Exception)
            {
                result = "-1";
            }
            return(result);
        }