示例#1
0
        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
        }
示例#2
0
 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());
 }