Example #1
0
        public IActionResult OnPost()
        {
            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 { restaurantId = Restaurant.Id }));
        }
Example #2
0
        public IActionResult OnPost(int restaurantId)
        {
            try
            {
                var restaurant = restaurantData.Delete(restaurantId);
                restaurantData.Commit();

                if (restaurant == null)
                {
                    return(RedirectToPage("./NotFound"));
                }

                TempData["Message"] = $"{restaurant.Name} deleted !!";
                return(RedirectToPage("./List"));
            }
            catch (Exception ex)
            {
                throw new Exception($"Some error has occuured : {guidService.GetGuid()}");
            }
        }
Example #3
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                Cuisines = htmlHelper.GetEnumSelectList <CusisineType>();
                return(Page());
            }
            if (Restaurant.Id > 0)
            {
                restaurantData.UpdateRestaurant(Restaurant);
            }
            else
            {
                restaurantData.AddRestaurant(Restaurant);
            }

            restaurantData.Commit();
            TempData["Message"] = $"Restaurant {Restaurant.Name} saved";
            return(RedirectToPage("./List"));
        }
Example #4
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (Restaurant.Id > 0)
            {
                _restaurantData.Update(Restaurant);
            }
            else
            {
                _restaurantData.Add(Restaurant);
            }

            _restaurantData.Commit();
            TempData["Message"] = "restaurant saved!";
            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
        }
Example #5
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)//Checking for Input Validation
            {
                Cuisines = htmlHelper.GetEnumSelectList <CuisineType>();

                return(Page());
            }
            if (Restaurants.Id > 0)
            {
                restaurantData.Update(Restaurants);
            }
            else
            {
                restaurantData.Add(Restaurants);
            }
            TempData["Message"] = "Saved Restaurant";
            restaurantData.Commit();
            return(RedirectToPage("./Detail", new { restaurantId = Restaurants.Id }));
            //return RedirectToPage("./List");
        }
Example #6
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                Cuisines = htmlHelper.GetEnumSelectList <CuisineType>();
                return(Page()); // this one will loose all changes if the user refreshes the browser
            }

            if (Restaurant.Id > 0)
            {
                Restaurant = restaurantData.Update(Restaurant);
            }
            else
            {
                restaurantData.Add(Restaurant);
            }

            restaurantData.Commit();
            TempData["Message"] = "Restaurant Saved!";                                // will be cleaned automatically
            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id })); // this fix the refresh issue
        }
Example #7
0
 public IActionResult OnPost()
 {
     /*PRG - post, redirect, get. You don't want to stay on a page with post request after submiting the form
      * as post resubmission is conceptually bad idea*/
     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!";             //this disapperars after the first request
     return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id, TempData }));
 }
Example #8
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                //throw NotImplementedException();
                return(Page());
            }

            if (Restaurant.Id > 0)
            {
                _restaurantData.Update(Restaurant);
            }
            else
            {
                _restaurantData.Add(Restaurant);
            }

            _restaurantData.Commit();
            TempData["Message"] = "Zapisano Restauracjê!";
            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
        }
Example #9
0
 public IActionResult OnPost()
 {
     //post-redirect-get pattern - after a post operation redirect to a get page to avoid resubmitting a post action
     if (!ModelState.IsValid)
     {
         Cuisines = htmlHelper.GetEnumSelectList <CuisineType>();
         return(Page());
     }
     if (Restaurant.Id > 0)
     {
         Restaurant          = restaurantData.Update(Restaurant);
         TempData["Message"] = "Restaurant updated.";
     }
     else
     {
         Restaurant          = restaurantData.Add(Restaurant);
         TempData["Message"] = "Restaurant added.";
     }
     restaurantData.Commit();
     return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
 }
Example #10
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid) // populate the page.
            {
                Cuisines = HtmlHelper.GetEnumSelectList <CuisineType>();
                return(Page());
            }

            if (restaurant.Id > 0) // edit existing new restaurant
            {
                restaurant = restaurantData.Update(restaurant);
            }
            else // add a new restaurant
            {
                restaurantData.Add(restaurant);
            }

            restaurantData.Commit();
            TempData["Message"] = "Restaurant saved!";
            return(RedirectToPage("./Detail", new { restaurantId = restaurant.Id }));
        }
Example #11
0
        public IActionResult OnPost()
        {
            //use Model State to check if all the information that was sent from the post
            //is valid or not. did it pass the Required and StringLength data annotations?
            //if it is valid, then we save it. if not valid, present the edit form again for user to fix errors
            if (!ModelState.IsValid)
            {
                //need to build the Cuisine select items again.
                //asp.net is stateless, so will not automatically have all the
                //info for cuisine still. need to build it again
                Cuisines = htmlHelper.GetEnumSelectList <CuisineType>();
                return(Page());
            }

            //if the id is greater than 0, that means its an edit. so we Update
            if (Restaurant.Id > 0)
            {
                restaurantData.Update(Restaurant);
            }
            //id isn't greater than 0, so we know we are adding a restaurant, not editing
            else
            {
                restaurantData.Add(Restaurant);
            }
            restaurantData.Commit();
            //we need to send a confirmation message to the user
            //we will use TempData. Add an object called Message to tempdata
            //tempdata is temporary. after the next request, the temp data disappears
            TempData["Message"] = "Restaurant Saved!";
            //after save is clicked, the user will be redirected to the detail page
            //the details page needs the restaurant id to get the info for it
            //so we send an anonymous object with the restaurant id in it
            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));

            //need some kind of form validation in case user leaves fields empty
            //asp.net core has an easy way to do this. no if else statements
            //add attributes to your model objects. Add attributes to Restaurant in OdeToFood.Core
            //we added the [Required] and [StringLength] data annotations to the Restaurant.cs file in OdeToFood.Core
            //look in that file to find more info on what that does.
        }
Example #12
0
        public IActionResult OnPost()
        {
            //To check all the information passed via model binding is valid like all the validaiton checks
            if (!ModelState.IsValid)
            {
                Cuisines = htmlHelper.GetEnumSelectList <CuisineType>();
                return(Page());
            }

            if (Restaurant.Id > 0)
            {
                restaurantData.Update(Restaurant);
            }
            else
            {
                restaurantData.Add(Restaurant);
            }
            restaurantData.Update(Restaurant);
            restaurantData.Commit();
            TempData["Message"] = "Restaurant saved!";
            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
        }
Example #13
0
        // OnPost for editing/adding a restaurant
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                Cuisines = htmlHelper.GetEnumSelectList <CuisineType>(); // Data binding for the drop down select, look at the htmlHelper
                return(Page());
            }

            if (Restaurant.Id > 0)
            {
                Restaurant = restaurantData.Update(Restaurant);
            }
            else
            {
                Restaurant = restaurantData.Add(Restaurant);
            }

            restaurantData.Commit();
            TempData["Message"] = "Restaurant saved!"; // This isn't inserted into the method below, it is a special dictionary
            // Arguments here: redirect to the detail page, with a new anonymous method of the ID
            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
        }
Example #14
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                Cusines = _helper.GetEnumSelectList <CuisineType>();
                return(Page());
            }


            if (Restaurant.Id > 0)
            {
                _restaurantData.UpdateRestaurant(Restaurant);
            }
            else
            {
                _restaurantData.AddRestaurant(Restaurant);
            }

            TempData["Message"] = "Restaurant saved successfully";
            _restaurantData.Commit();
            return(RedirectToPage("./Details", new { restaurantId = Restaurant.Id }));
        }
Example #15
0
        public IActionResult OnPost()
        {
            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 { restaurantId = Restaurant.Id }));
            // To jest wzór POST-GET-REDIRECT, który automatycznie przekierowuje użytkownika dalej
        }
Example #16
0
        public IActionResult OnPost()
        {
            //ModelState["Address"].Errors  -> if required and passed empty , shows an error


            if (!ModelState.IsValid) //-> checks all validations
            {
                Cuisines = htmlHelper.GetEnumSelectList <CuisineType>();
                return(Page());
            }
            if (Restaurant.Id > 0)
            {
                Restaurant = restaurantData.Update(Restaurant); //2 way binded Restaurant ,
            }
            else
            {
                restaurantData.AddRestaurant(Restaurant);
            }
            restaurantData.Commit();
            TempData["Message"] = "Restaurant Saved: " + Restaurant.Name.ToUpper();
            return(RedirectToPage("Detail", new { restaurantId = Restaurant.Id }));
        }
Example #17
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                Cuisines = htmlHelper.GetEnumSelectList <CuisineType>(); //needs to update on 'POST'
                return(Page());
            }

            if (Restaurant.Id > 0)
            {
                restaurantData.Update(Restaurant);
            }
            else
            {
                restaurantData.Add(Restaurant);
            }
            restaurantData.Commit();

            TempData["Message"] = "Restaurant Saved";                                 //TempData linked to Detail member Message.

            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id })); //routes to respected Restaurant's Detail page via Id
        }
Example #18
0
        public IActionResult OnPost()
        {
            string message = string.Empty;

            if (!ModelState.IsValid)
            {
                Cuisines = _htmlHelper.GetEnumSelectList <CuisineType>();
                return(Page());
            }
            if (Restaurant.Id > 0)
            {
                Restaurant          = _restaurantData.Update(Restaurant);
                TempData["Message"] = "Restaurant Updated!!";
            }
            else
            {
                _restaurantData.Add(Restaurant);
                TempData["Message"] = "Restaurant Saved!!";
            }
            _restaurantData.Commit();
            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
        }
Example #19
0
        public IActionResult OnPost()
        {
            Cuisines = htmlHelper.GetEnumSelectList <CuisineType>(); // need again in post method ... for populating during post operation
            if (ModelState.IsValid)
            {
                if (Restaurant.Id > 0)
                {
                    //Restaurant = restaurantData.UpdateRestaurant(Restaurant); this also works
                    restaurantData.UpdateRestaurant(Restaurant); //this is able to work due to model binding
                }
                else
                {
                    restaurantData.AddRestaurant(Restaurant);
                }
                TempData["Message"] = "Restaurant saved!";
                restaurantData.Commit();
                return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
                //return RedirectToPage("./Detail/" + Restaurant.Id);
            }

            return(Page());
        }
Example #20
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                if (Restaurant.Id == 0)
                {
                    Restaurant          = restaurantData.Create(Restaurant);
                    TempData["Message"] = "The Object is created!";
                }
                else
                {
                    Restaurant          = restaurantData.Update(Restaurant);
                    TempData["Message"] = "The Object is updated!";
                }

                restaurantData.Commit();
                return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
            }

            CuisineTypes = htmlHelper.GetEnumSelectList <CuisineType>();
            return(Page());
        }
 //ON POST METHOD FOR UPDATING DATA
 public IActionResult OnPost()
 {
     //WILL PERFORM VALIDATION CHECKS BASED ON RESTAURANT CLASS
     if (!ModelState.IsValid)
     {
         Cuisines = htmlHelper.GetEnumSelectList <CuisineType>();
         return(Page());
     }//IS THIS A NEW RESTAURANT OR UPDATE?
     if (Restaurant.Id > 0)
     {
         restaurantData.Update(Restaurant);
     }
     else
     {
         restaurantData.Add(Restaurant);
     }
     //COMMIT CHANGES
     restaurantData.Commit();
     //TEMP DATA WORKS FOR NEXT PAGE REQUEST ONLY..THEN IT GONE
     TempData["Message"] = "Restaurant saved!";
     return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
 }
Example #22
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                Cuisine = htmlHelper.GetEnumSelectList <CuisineType>();
                return(Page());
            }
            if (Restaurant.id > 0)
            {
                restaurantData.Update(Restaurant);
            }
            else
            {
                Restaurant.Name = Restaurant.Name.ToUpper();
                restaurantData.Add(Restaurant);
            }

            restaurantData.Commit();
            TempData["Message"] = "Restaurant Saved";
            return(RedirectToPage("./detail", new { restaurantId = Restaurant.id }));
            //Restaurant= restaurantData.Update(Restaurant);
            //restaurantData.Commit();
        }
Example #23
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                Cuisine = htmlHelper.GetEnumSelectList <CuisineType>();
                return(Page());
            }

            if (Restaurant.Id > 0)
            {
                Restaurant = restaurantData.Update(Restaurant);
            }
            else
            {
                restaurantData.Add(Restaurant);
            }
            restaurantData.Commit();

            //on the next request to this application, any page in the application can look into
            // tempData and see this message and pull it out. This is , as the name implies, temporary
            TempData["Message"] = "Restaurant saved!";
            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
        }
Example #24
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                // asp.net core is stateless, so rebuild of Cuisines is required when posting
                Cuisines = htmlHelper.GetEnumSelectList <CuisineType>();
                return(Page());
            }

            if (Restaurant.Id > 0)
            {
                // assumes the id is the same that's on the form.
                restaurantData.Update(Restaurant);
            }
            else
            {
                restaurantData.Add(Restaurant);
            }

            restaurantData.Commit();
            TempData["Message"] = "Restrauant saved.";
            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
        }
        public IActionResult OnPost()
        {
            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!";

            //Avoids user accidently reload page and sending post request twice.
            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
        }
Example #26
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                Cuisines = htmlHelper.GetEnumSelectList <CuisineType>(); //cos it is stateless, we need to build it during post as well
                return(Page());
            }

            if (Restaurant.Id > 0)
            {
                Restaurant = restaurantData.UpdateRestaurant(Restaurant);
            }
            else
            {
                Restaurant = restaurantData.AddRestaurant(Restaurant);
            }

            TempData["Message"] = "Restaurant information saved successfully !";

            restaurantData.Commit();

            return(RedirectToPage("./Detail", new { restId = Restaurant.Id }));
        }
        public IActionResult OnPost(int?id)
        {
            EditMode = id.HasValue;

            if (!ModelState.IsValid)
            {
                CuisineSelectItems = _htmlHelper.GetEnumSelectList <CuisineType>();
                return(Page());
            }

            if (EditMode)
            {
                _restaurantData.Update(Restaurant);
            }
            else
            {
                _restaurantData.Add(Restaurant);
            }
            _restaurantData.Commit();

            TempData["Message"] = "Restaurant saved!";
            return(RedirectToPage("./Details", new { id = Restaurant.Id }));
        }
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                CreateCuisinesItens();
                return(Page());
            }

            if (Restaurant.Id > 0)
            {
                restauranteData.Update(Restaurant);
            }
            else
            {
                restauranteData.Add(Restaurant);
            }

            restauranteData.Commit();

            TempData["Message"] = "Restaurant Saved!";

            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
        }
Example #29
0
        //el post solo se usa para enviar datos
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                //siempre se tiene que enviar cousines ya que no hay estado y los valores se pierden
                Cousines = HtmlHelper.GetEnumSelectList <CousineType>();
                return(Page());
            }

            if (Restaurant.Id > 0)
            {
                Restaurant = RestaurantData.Update(Restaurant);
            }
            else
            {
                Restaurant = RestaurantData.Add(Restaurant);
            }

            RestaurantData.Commit();

            //aca se llena el temdata que se va a pasar a la pagina de detail
            TempData["Message"] = "Restaurant Saved!";
            return(RedirectToPage("./Detail", new { restaurantId = Restaurant.Id }));
        }
 public IActionResult OnPost()
 {
     //if Location with empty string will be handled
     //ModelState["Location"].Errors;
     Cusines = _htmlHelper.GetEnumSelectList <Core.CuisineType>();
     if (!ModelState.IsValid)
     {
         //if all info that passed in via model binding are not valid ?
         //update data
         return(Page());
     }
     if (Restaurant.Id > 0)
     {
         _restaurantData.Update(Restaurant);
     }
     else
     {
         _restaurantData.AddOrCreate(Restaurant);
     }
     _restaurantData.Commit();
     //Dictionary
     TempData["Message"] = "Restaurant Saved Successfully!";
     return(RedirectToPage("./Details", new { restaurantId = Restaurant.Id }));
 }