public IActionResult OnPost() { //if (ModelState.IsValid) //{ // Cuisines = HtmlHelper.GetEnumSelectList<CuisineType>(); // Restaurant = RestaurantData.Update(Restaurant); // //PRG - Post Redirect to Get // return RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }); //} //RestaurantData.Commit(); //return Page(); if (!ModelState.IsValid) { Cuisines = HtmlHelper.GetEnumSelectList <CuisineType>(); return(Page()); } if (Restaurant.Id > 0) { Restaurant = RestaurantData.Update(Restaurant); } else { RestaurantData.Add(Restaurant); } TempData["Message"] = "Restaurant Saved"; RestaurantData.Commit(); return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id })); }
public IActionResult OnPost() { if (!ModelState.IsValid) { Cuisines = HtmlHelper.GetEnumSelectList <CusineType>(); return(Page()); } Restaurant = Restaurant.Id > 0 ? RestaurantData.Update(Restaurant): RestaurantData.Add(Restaurant); _ = RestaurantData.Commit(); TempData["Message"] = "Restaurant saved."; return(RedirectToPage("./Details", new { Restaurant.Id })); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } if (Restaurant.Id > 0) { TempData["Message"] = "Restaurant updated!"; Restaurant = RestaurantData.Update(Restaurant); } else { TempData["Message"] = "Restaurant added!"; Restaurant = RestaurantData.Add(Restaurant); } RestaurantData.Commit(); return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id })); }