public ActionResult Insert(DealerAddressVM item) { ViewBag.CityID = new SelectList(cits.GetActive(), "ID", "CityName", item.CityID); ViewBag.CountryID = new SelectList(cnts.GetActive(), "ID", "CountryName", item.CountryID); if (ModelState.IsValid) { Dealer d = new Dealer(); d.Name = item.Name; d.MainPhone = item.MainPhone; Address a = new Address(); a.Street = item.Street; a.PostalCode = item.PostalCode; a.CityID = item.CityID; City c = cits.GetByID(item.CityID); if (c.Country == null) { c.CountryID = item.CountryID; cits.Update(c); } adrs.Add(a); d.AddressID = a.ID; bool sonuc = ds.Add(d); if (sonuc) { return(RedirectToAction("Index")); } } else { ViewBag.Message = "Invalid format."; } return(View()); }