public ActionResult AddEditCity(int id = 0, int pid = 0)
        {
            CustomMethods.ValidateRoles("City");
            if (!Convert.ToBoolean(Session["IsAdd"]) && !Convert.ToBoolean(Session["IsEdit"]))
            {
                return(View("ErrorPage", "Error"));
            }
            CityModel CityModel = new CityModel();
            int       take      = 10;
            int       skip      = take * pid;

            CityModel.PageID  = pid;
            CityModel.Current = pid + 1;
            ViewBag.c         = CityModel.PageID;
            if (id != 0)
            {
                var objcity = new CityBLL {
                }.GetSubCityById(id);
                if (objcity != null)
                {
                    CityModel.CityId   = objcity.CityId;
                    CityModel.CityName = objcity.CityName;
                    CityModel.StateId  = objcity.StateId;
                    CityModel.IsActive = Convert.ToBoolean(objcity.IsActive);
                }
            }
            CustomMethods.BindStateList(CityModel);
            return(View(CityModel));
        }
        public ActionResult AddEditCity(CityModel model)
        {
            int     result  = 0;
            CityBLL CityBLL = new CityBLL();

            try
            {
                if (model.CityId == 0)
                {
                    if (!Convert.ToBoolean(Session["Add"]))
                    {
                        return(View("ErrorPage"));
                    }
                }
                else
                {
                    if (!Convert.ToBoolean(Session["Edit"]))
                    {
                        return(View("ErrorPage"));
                    }
                }
                if (ModelState.IsValid)
                {
                    if (model.CityId == 0)
                    {
                        var checkDuplicate = objdb.Cities.Where(x => x.CityName == model.CityName).FirstOrDefault();
                        if (checkDuplicate == null)
                        {
                            int res = new CityBLL {
                            }.AddEditCity(new CityModel
                            {
                                CityName  = model.CityName,
                                StateId   = model.StateId,
                                IsActive  = model.IsActive,
                                CreatedBy = Convert.ToInt32(Session["UserId"]),
                            });
                            if (res != 0)
                            {
                                Session["Success"] = "Successfully Added The Record";
                                return(RedirectToAction("City"));
                            }
                        }
                        Session["Error"] = "Record Already Exists";
                        return(RedirectToAction("City"));
                    }


                    else
                    {
                        if (model.CityId == 0)
                        {
                            Session["Error"] = "Record Already Exists";
                            return(RedirectToAction("AddEditCity"));
                        }
                        else
                        {
                            model.UpdatedBy = Convert.ToInt32(Session["UserId"]);
                            result          = CityBLL.AddEditCity(model);

                            if (result != 0)
                            {
                                Session["Success"] = "Successfully Updated The Record";
                                return(RedirectToAction("City"));
                            }
                        }
                    }
                }
                CustomMethods.BindStateList(model);
                return(View(model));
            }
            catch (Exception)
            {
                Session["Error"] = "An Error has occured";
                CustomMethods.BindCountryList(model);
                return(View(model));

                throw;
            }
        }