public IActionResult Edit(int id) { if (_sessionManager.User is not null) { Restaurant resto = _restaurantService.Get(id); RestaurantUpdForm start = new RestaurantUpdForm() { Id = id, Name = resto.Name, VAT = resto.VAT, Address1 = resto.Address1, Address2 = resto.Address2, City = resto.City, Zip = resto.Zip, SelectedCountry = resto.Country, Countries = GetCountries(), Email = resto.Email, Closed = resto.Closed }; return(View(start)); } else { return(RedirectToAction("Login", "Auth")); } }
public IActionResult Edit(int id, RestaurantUpdForm form) { if (_sessionManager.User is not null) { try { if (ModelState.IsValid) { Restaurant resto = new Restaurant() { Id = id, Name = form.Name, VAT = form.VAT, Address1 = form.Address1, Address2 = form.Address2, City = form.City, Zip = form.Zip, Country = form.SelectedCountry, Email = form.Email, Closed = form.Closed }; bool updated = _restaurantService.Upd(resto); if (!updated) { ViewBag.Message = "Error: Restaurant NOT Updated (" + id.ToString() + ")"; } return(RedirectToAction("index")); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); //ViewBag.Error = ex.Message; } return(View()); } else { return(RedirectToAction("Login", "Auth")); } }