Пример #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
        }
 public ActionResult Edit(Restaurant resto)
 {
     try
     {
         _resto.Update(resto);
         ViewData["Pesan"] =
             $"<span class='alert alert-success'>Data berhasil diupdate</span>";
         return(View(resto));
     }
     catch (Exception ex)
     {
         ViewData["Pesan"] =
             $"<span class='alert alert-danger'>Data resto {resto.Name} gagal diupdate, {ex.Message}</span>";
         return(View(resto));
     }
 }
Пример #3
0
        public IActionResult OnPost()
        {
            // Because ASP.Net core is stateless so OnPost() request Cuisines Enum will be lost
            // as populated by OnGet()
            Cuisines = htmlHelper.GetEnumSelectList <CuisineType>();

            if (ModelState.IsValid)                // Validating Data Annotations using IsValid Property
            {                                      // if any validation error occurs then it is saved in
                                                   // ModelState["Location"].Errors collection (for Restaurant.Location field only)
                RestaurantData.Update(Restaurant); // Yha pr restaurant avail kese hua
                RestaurantData.commit();
                // As post must redirect to some Get req page so the changes might not
                // get submitted again if user refreshes the page
                return(RedirectToPage("./RestaurantDetails", new { RestaurantId = Restaurant.id }));
            }

            return(Page());
        }