public ActionResult Edit(int id) { var temp = _context.Apartments.FirstOrDefault(t => t.Id == id); ApartmentsEditViewModel model = new ApartmentsEditViewModel() { DistrictName = temp.DistrictName, Name = temp.Name, Parking = temp.Parking, Picture = temp.Picture, Price = temp.Price, Repair = temp.Repair, Square = temp.Square, StreetName = temp.StreetName, Warming = temp.Warming, City = temp.City, Floor = temp.Floor, CountRooms = temp.CountRooms, Id = temp.Id }; return(View(model)); }
public ActionResult Edit(ApartmentsEditViewModel model) { model.Name = "р-н" + model.DistrictName + ", вул." + model.StreetName; if (ModelState.IsValid) { var temp = _context.Apartments.FirstOrDefault(t => t.Id == model.Id); temp.DistrictName = model.DistrictName; temp.Name = model.Name; temp.Parking = model.Parking; temp.Picture = model.Picture; temp.Price = model.Price; temp.Repair = model.Repair; temp.Square = model.Square; temp.StreetName = model.StreetName; temp.Warming = model.Warming; temp.City = model.City; temp.Floor = model.Floor; temp.CountRooms = model.CountRooms; _context.SaveChanges(); return(RedirectToAction("Index", "Apartments")); } return(View(model)); }