public IActionResult OnPost() { //requirements have been set on the entity //check the model state for validation if (!ModelState.IsValid) { Cuisines = HtmlHelper.GetEnumSelectList <CuisineType>(); return(Page()); } if (Restaurant.Id > 0) { RestaurantData.Update(Restaurant); } else { RestaurantData.Add(Restaurant); } RestaurantData.Commit(); TempData["Message"] = "Restaurant saved!"; return(RedirectToPage("./Detail", new { id = this.Restaurant.Id })); //using the new{}, creates an anonymously typed object }
public IActionResult OnPost(int restaurantId) { var restaurant = RestaurantData.Delete(restaurantId); RestaurantData.Commit(); if (restaurant == null) { return(RedirectToPage("./NotFound")); } TempData["Message"] = $"{restaurant.Name} deleted"; return(RedirectToPage("./List")); }
public IActionResult OnPost(int restaurantId) { Restaurant = restaurantData.Delete(restaurantId); restaurantData.Commit(); if (Restaurant == null) { return(RedirectToPage("./notfound")); } else { TempData["Message"] = $"{ Restaurant.Name } is deleted"; return(RedirectToPage("./List")); } }
public IActionResult OnPost() { if (ModelState.IsValid) { if (Restaurant.Id < 1) { Restaurant = restaurantData.Add(Restaurant); } else { Restaurant = restaurantData.UpdateRestaurant(Restaurant); } restaurantData.Commit(); return(RedirectToPage("./details", new { restaurantId = Restaurant.Id })); } TempData["Message"] = "Restaurant saved"; Cuisines = htmlHelper.GetEnumSelectList <CuisineType>(); return(Page()); }