public ActionResult TalukList(long? CountryId, long? StateId, long? DistrictId)
 {
     sdtoDistrict district = new sdtoDistrict() { StateDetails = new sdtoState() { CountryId = CountryId == null ? 0 : CountryId.Value, StateId = StateId == null ? 0 : StateId.Value }, StateId = StateId == null ? 0 : StateId.Value, DistrictId = DistrictId == null ? 0 : DistrictId.Value };
     ViewBag.StateId = district.StateId;
     ViewBag.CountryId = district.StateDetails.CountryId;
     return View(district);
 }
        public ActionResult SaveDistrict(sdtoDistrict district)
        {
            sdtoUser userDetails = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser);
            if (userDetails == null)
                userDetails = new sdtoUser();

            if (ModelState.IsValid)
            {
                if (db.Districts.Count(x => x.DistrictName.Equals(district.DistrictName.Trim(), StringComparison.InvariantCultureIgnoreCase) && x.StateId == district.StateId && x.DistrictId != district.DistrictId) == 0)
                {
                    if (district.DistrictId == 0)
                    {
                        db.Districts.Add(new sdtoDistrict() { StateId = district.StateId, DistrictName = district.DistrictName, DistrictAbbr = district.DistrictAbbr, CreatedBy = userDetails.UserID, CreatedOn = DateTime.Now });
                    }
                    else
                    {
                        district.ModifiedBy = userDetails.UserID;
                        district.ModifiedOn = DateTime.Now;
                        db.Entry(district).State = EntityState.Modified;
                    }
                    db.SaveChanges();

                    var cn = db.States.Find(district.StateId);
                    return RedirectToAction("DistrictList", new { StateId = district.StateId, CountryId = cn.CountryId });
                }
                else
                    ModelState.AddModelError("DistrictName", "District already exists!!!");
            }

            var state = db.States.Find(district.StateId);
            ViewBag.CountryId = state.CountryId;
            return View(district);
        }
        public ActionResult SaveVillage(long TalukId, long VillageId = 0)
        {
            sdtoUser userDetails = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser);
            if (userDetails == null)
                userDetails = new sdtoUser();

            sdtoTaluk taluk = db.Taluks.Find(TalukId);
            if (taluk == null)
                taluk = new sdtoTaluk();
            var district = new sdtoDistrict();
            var state = new sdtoState();
            if (taluk != null)
                district = db.Districts.Find(taluk.DistrictId);

            if (district == null)
                district = new sdtoDistrict();

            if (district != null)
                state = db.States.Find(district.StateId);

            if (state == null)
                state = new sdtoState();

            sdtoVillage village = new sdtoVillage()
            {
                TalukId = taluk.TalukId
            };

            ViewBag.CountryId = state.CountryId;
            ViewBag.StateId = district.StateId;
            ViewBag.DistrictId = taluk.DistrictId;
            ViewBag.TalukId = taluk.TalukId;
            sdtoTaluk parent = db.Taluks.Find(taluk.TalukId);
            if (parent != null)
            {
                ViewBag.ParentId = parent.TalukId;
                village = db.Villages.Find(VillageId);
                if (village == null)
                    village = new sdtoVillage() { TalukId = parent.TalukId, TalukDetails = parent };
                else
                    village.TalukDetails = parent;
            }
            return View(village);
        }
        public ActionResult SaveDistrict(long CountryId, long StateId, long DistrictId = 0)
        {
            sdtoUser userDetails = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser);
            if (userDetails == null)
                userDetails = new sdtoUser();
            sdtoDistrict district = new sdtoDistrict();

            ViewBag.CountryId = CountryId;
            sdtoState parent = db.States.Find(StateId);
            if (parent != null)
            {
                ViewBag.ParentId = parent.StateId;
                district = db.Districts.Find(DistrictId);
                if (district == null)
                    district = new sdtoDistrict() { StateId = parent.StateId, StateDetails = parent };
                else
                    district.StateDetails = parent;
            }
            return View(district);
        }