コード例 #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
ファイル: Delete.cshtml.cs プロジェクト: JoshCrz/OdeToFood
        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"));
        }
コード例 #3
0
 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"));
     }
 }
コード例 #4
0
ファイル: edit.cshtml.cs プロジェクト: manjusaharan/CoreApp
 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());
 }