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 SaveState(long CountryId, long StateId = 0) { sdtoUser userDetails = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser); if (userDetails == null) userDetails = new sdtoUser(); sdtoCountry country = db.Countries.Find(CountryId); ViewBag.CountryList = new SelectList(db.Countries, "CountryId", "CountryName", CountryId); ViewBag.CountryId = CountryId; sdtoState state = db.States.Find(StateId); if (state == null) state = new sdtoState() { CountryId = country.CountryId, CountryDetails = country }; else state.CountryDetails = country; return View(state); }
public ActionResult SaveState(sdtoState state) { sdtoUser userDetails = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser); if (userDetails == null) userDetails = new sdtoUser(); if (ModelState.IsValid) { if (db.States.Count(x => x.StateName.Equals(state.StateName.Trim(), StringComparison.InvariantCultureIgnoreCase) && x.StateId != state.StateId && x.CountryId == state.CountryId) == 0) { if (state.StateId == 0) { db.States.Add(new sdtoState() { CountryId = state.CountryId, StateName = state.StateName, StateAbbr = state.StateAbbr, CreatedBy = userDetails.UserID, CreatedOn = DateTime.Now }); } else { state.ModifiedBy = userDetails.UserID; state.ModifiedOn = DateTime.Now; db.Entry(state).State = EntityState.Modified; } db.SaveChanges(); } else ModelState.AddModelError("StateName", "State already exists!!!"); return RedirectToAction("StateList", new { CountryId = state.CountryId }); } sdtoCountry country = db.Countries.Find(state.CountryId); ViewBag.CountryList = new SelectList(db.Countries, "CountryId", "CountryName", state.CountryId); ViewBag.CountryId = state.CountryId; state.CountryDetails = country; return View(state); }
public ActionResult DistrictList(long? CountryId, long? StateId) { sdtoState state = new sdtoState() { CountryId = CountryId == null ? 0 : CountryId.Value, StateId = StateId == null ? 0 : StateId.Value }; ViewBag.StateId = state.StateId; ViewBag.CountryId = state.CountryId; return View(state); }