public ActionResult Add(AddRestaurantViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var dbContext = new QuickRestaurantsEntities())
                {
                    var Restaurant = new Restaurant
                    {
                        RestaurantID = model.RestaurantID,
                        Name         = model.Name,
                        Address      = model.Address,
                        Mobile       = model.Mobile,
                        Website      = model.Website,
                        Time         = model.Time,
                        Days         = model.Days,
                    };
                    dbContext.Restaurants.Add(Restaurant);

                    try
                    {
                        dbContext.SaveChanges();
                        ViewBag.Message = "Successful";
                    }
                    catch (Exception e)
                    {
                        ViewBag.Message = "Failed";
                    }
                }
            }
            return(View());
        }
Exemplo n.º 2
0
        public void PostRestaurant(AddRestaurantViewModel model)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("Couldn't add a restaurant");
            }
            var restaurant = Mapper.Map <AddRestaurantViewModel, Restaurant>(model);

            restaurantService.AddRestaurant(restaurant);
        }
Exemplo n.º 3
0
        public void Should_not_have_error_when_values_are_specified()
        {
            //Arrange
            var restaurant = new AddRestaurantViewModel()
            {
                MenuUrl    = "http://menu.url",
                WebsiteUrl = "http://website.url",
                Name       = "Name",
                Phone      = "12232213321"
            };

            //Act
            ValidationResult validationResult = validator.Validate(restaurant);

            //Assert
            Assert.True(validationResult.IsValid);
        }
        public IActionResult Add(AddRestaurantViewModel addRestaurantViewModel)
        {
            if (ModelState.IsValid)
            {
                Restaurant newRestaurant = new Restaurant
                {
                    Name    = addRestaurantViewModel.Name,
                    Address = addRestaurantViewModel.Address,
                    Phone   = addRestaurantViewModel.Phone
                };
                //Restaurant.Add(newRestaurant);
                context.Restaurants.Add(newRestaurant);
                context.SaveChanges();

                return(Redirect("/Restaurant"));
            }

            return(View(addRestaurantViewModel));
        }
        //Method to add new restaurant to existing list

        public IActionResult AddRestaurant(AddRestaurantViewModel addRestaurantViewModel)
        {
            if (ModelState.IsValid)
            {
                Restaurant newRestaurant = new Restaurant
                {
                    Name    = addRestaurantViewModel.Name,
                    Address = addRestaurantViewModel.Address,
                    Nuts    = addRestaurantViewModel.Nuts,
                    Dairy   = addRestaurantViewModel.Dairy,
                    Soy     = addRestaurantViewModel.Soy
                };
                //adds to database making changes
                context.Restaurants.Add(newRestaurant);
                //saves above changes to database
                context.SaveChanges();

                return(Redirect("/Restaurant"));
            }
            return(View(addRestaurantViewModel));
        }
Exemplo n.º 6
0
        public void AddRestaurantViewModelShouldBeMappedToRestaurant()
        {
            //Arrange
            var restaurantViewModel = new AddRestaurantViewModel();

            restaurantViewModel.MenuUrl    = "http://menumock.url";
            restaurantViewModel.WebsiteUrl = "http://mock.url";
            restaurantViewModel.Name       = "MockName";
            restaurantViewModel.Phone      = "123456789";


            //Act
            var restaurant = Mapper.DynamicMap <AddRestaurantViewModel, Restaurant>(restaurantViewModel);

            //Assert
            Assert.Equal(restaurant.MenuUrl, restaurantViewModel.MenuUrl);
            Assert.Equal(restaurant.WebsiteUrl, restaurantViewModel.WebsiteUrl);
            Assert.Equal(restaurant.Name, restaurantViewModel.Name);
            Assert.Equal(restaurant.Phone, restaurantViewModel.Phone);
            Assert.IsType <Restaurant>(restaurant);
        }
Exemplo n.º 7
0
        public IActionResult Add(AddRestaurantViewModel addRestaurantViewModel)
        {
            RestaurantCategory newRestaurantCategory = context.Categories.Single(c => c.ID == addRestaurantViewModel.CategoryID);

            if (ModelState.IsValid)
            {
                Restaurant newRestaurant = new Restaurant
                {
                    Name             = addRestaurantViewModel.Name,
                    Notes            = addRestaurantViewModel.Notes,
                    Category         = newRestaurantCategory,
                    RestaurantStatus = addRestaurantViewModel.RestaurantStatus
                };


                context.Restaurants.Add(newRestaurant);
                context.SaveChanges();

                return(Redirect("/Restaurant"));
            }

            return(View(addRestaurantViewModel));
        }
        //Method to create a form to add a restaurant to a list of restaurants
        public IActionResult AddRestaurant()
        {
            AddRestaurantViewModel addRestaurantViewModel = new AddRestaurantViewModel();

            return(View(addRestaurantViewModel));
        }
Exemplo n.º 9
0
        public IActionResult Add()
        {
            AddRestaurantViewModel addRestaurantViewModel = new AddRestaurantViewModel(context.Categories.ToList());

            return(View(addRestaurantViewModel));
        }