예제 #1
0
        public IActionResult Edit(int id, [Bind("Id,Name,Address,Description,Rate,ImageUrl,PhoneNumber,WorkingHours,DeliveryAreas,MenuId")] Restaurant restaurant)
        {
            if (id != restaurant.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _restRepo.UpdateRestaurant(restaurant);
                    _restRepo.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_restRepo.RestaurantExists(restaurant.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MenuId"] = new SelectList(_menuRepo.AllMenus, "Id", "Id");

            return(View(restaurant));
        }
예제 #2
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         dbContext.UpdateRestaurant(Restaurant);
         return(RedirectToAction("Details", "Home", new { id = Restaurant.ID }));
     }
     return(Page());
 }
예제 #3
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());
 }