public ActionResult SaveCountry(AddCountries model) { int id = (int)Session["admin"]; ModelState.Remove("Id"); if (!ModelState.IsValid) { return(View("AddCountries", model)); } var countryInDb = _context.GetCountry(model.Id); if (countryInDb == null) { Country country = new Country { Name = model.CountryName, CountryCode = model.CountryCode, CreatedDate = DateTime.Now, CreatedBy = id, ModifiedDate = DateTime.Now, ModifiedBy = id, IsActive = true }; _context.AddCountry(country); return(RedirectToAction("ManageCountries", "Admin")); } else { countryInDb.Name = model.CountryName; countryInDb.CountryCode = model.CountryCode; countryInDb.ModifiedDate = DateTime.Now; countryInDb.ModifiedBy = id; countryInDb.IsActive = true; _context.UpdateUp(); return(RedirectToAction("ManageCountries", "Admin")); } }