Ejemplo n.º 1
0
        public async Task Create_WhenCalled_CreateCustomerInDbAndRedirectToIndex()
        {
            // Arrange
            var model = new  RestaurantCreateViewModel
            {
                Name        = "Serving You",
                Phone       = "02 1111 2222",
                Email       = "*****@*****.**",
                Description = "Fantastic Restaurant",
                Postcode    = "2000",
                StateCode   = "NSW",
                Unit        = "1",
                Street      = "Queen",
                Town        = "Sydney",
                //DateCreated = new DateTime(2020, 11, 1)
            };

            // Act
            var result = await controller.Create(model) as RedirectToActionResult;

            // Assert
            repository.Verify(r => r.Add(It.IsAny <Restaurant>()), Times.Once);
            unitOfWork.Verify(u => u.CompleteAsync(), Times.Once);
            Assert.That(result.ActionName, Is.EqualTo("index").IgnoreCase);
        }
Ejemplo n.º 2
0
        public bool AddRestaurant(RestaurantCreateViewModel restaurants)
        {
            connection();
            SqlCommand com = new SqlCommand("Post_Add_Restaurant", con);

            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.AddWithValue("@cityId", restaurants.City_ID);
            com.Parameters.AddWithValue("@address", restaurants.Addresses);
            com.Parameters.AddWithValue("@name", restaurants.Restaurant_Name);
            com.Parameters.AddWithValue("@description", restaurants.Restaurant_Description);
            com.Parameters.AddWithValue("@hours", restaurants.Opening_Hours);
            com.Parameters.AddWithValue("@details", restaurants.Other_Details);
            //         com.Parameters.AddWithValue("@geom", restaurants.Add_geom);
            com.Parameters.AddWithValue("@typeKitchenId", restaurants.TypeKitchen);
            com.Parameters.AddWithValue("@star", restaurants.Star);


            con.Open();
            int i = com.ExecuteNonQuery();

            con.Close();
            if (i >= 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task <IActionResult> Create(RestaurantCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var restaurant = new Restaurant
                {
                    Name        = model.Name,
                    Phone       = model.Phone,
                    Email       = model.Email,
                    Description = model.Description,
                    Postcode    = model.Postcode,
                    Unit        = model.Unit,
                    Street      = model.Street,
                    Town        = model.Town,
                    StateCode   = model.StateCode,
                    DateUpdated = DateTime.Now
                };

                repository.Add(restaurant);
                await unitOfWork.CompleteAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
        // GET: Restaurant/Create
        public async Task <IActionResult> Create()
        {
            var restaurant = new RestaurantCreateViewModel
            {
                StateList = await repository.GetStatesAsync()
            };

            return(View(restaurant));
        }
Ejemplo n.º 5
0
 public virtual ActionResult Create(RestaurantCreateViewModel restaurantCreateViewModel)
 {
     if (ModelState.IsValid)
     {
         var restaurant = Mapper.Map <Restaurant>(restaurantCreateViewModel);
         _restaurantRepository.Add(restaurant);
         return(RedirectToAction(Views.ViewNames.Index));
     }
     return(View(""));
 }
        public IActionResult Create(RestaurantCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.ResetCategoryList(context);
                return(View(model));
            }

            model.Persist(context);
            return(RedirectToAction(actionName: nameof(Index)));
        }
Ejemplo n.º 7
0
        public ActionResult Create(RestaurantCreateViewModel restaurantCreate)
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <RestaurantCreateViewModel, Restaurant>());
            var mapper = config.CreateMapper();

            Restaurant restaurant = mapper.Map <Restaurant>(restaurantCreate);

            restaurant.UserId = Convert.ToInt32(Session["UserId"]);
            _restaurantContext.Insert(restaurant);

            return(RedirectToAction("Index", "RestaurantAdmin"));
        }
Ejemplo n.º 8
0
 public ActionResult AddRestaurant(RestaurantCreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (restauntRepository.AddRestaurant(model))
         {
             TempData["message"] = $"Ресторан успешно создан";
             return(RedirectToAction("GetAllRestaurants", "Restaurant"));
         }
     }
     return(View());
 }
Ejemplo n.º 9
0
        public IActionResult RestaurantCreate(RestaurantCreateViewModel model)
        {
            Restaurant restaurant = new Restaurant
            {
                Naam    = model.Naam,
                TypeId  = _restaurantTypeService.Get(model.TypeId).Id,
                NogOpen = true
            };

            _restaurantService.Insert(restaurant);

            return(RedirectToAction("RestaurantDetail", new { id = restaurant.Id }));
        }
Ejemplo n.º 10
0
        public IActionResult RestaurantCreate()
        {
            List <SelectListItem>        typesList = new List <SelectListItem>();
            IEnumerable <RestaurantType> types     = _restaurantTypeService.Get();

            foreach (var type in types)
            {
                typesList.Add(new SelectListItem {
                    Value = type.Id.ToString(), Text = type.Naam
                });
            }
            RestaurantCreateViewModel vm = new RestaurantCreateViewModel
            {
                TypeList = typesList
            };

            return(View(vm));
        }
Ejemplo n.º 11
0
        public ActionResult Create(RestaurantCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            Restaurant restaurant = new Restaurant();

            restaurant.Name      = model.Name;
            restaurant.Address   = model.Address;
            restaurant.Email     = model.Email;
            restaurant.OpenHour  = model.OpenHour;
            restaurant.CloseHour = model.CloseHour;
            restaurant.Phone     = model.Phone;
            restaurant.Capacity  = model.Capacity;
            restaurant.ManagerId = model.ManagerId;
            RestaurantsRepository repository = new RestaurantsRepository();

            repository.Insert(restaurant);
            return(RedirectToAction("Index"));
        }
 public ActionResult Create(RestaurantCreateViewModel model)
 {
     if (!ModelState.IsValid)
     {
         UsersRepository rep = new UsersRepository();
         ViewBag.ManagerId = new SelectList(rep.GetAll(), "Id", "Name");
         return(View());
     }
     else
     {
         Restaurant restaurant = new Restaurant();
         restaurant.Name      = model.Name;
         restaurant.Address   = model.Address;
         restaurant.Email     = model.Email;
         restaurant.OpenHour  = model.OpenHour;
         restaurant.CloseHour = model.CloseHour;
         restaurant.Phone     = model.Phone;
         restaurant.Capacity  = model.Capacity;
         restaurant.ManagerId = model.ManagerId;
         RestaurantsRepository repository = new RestaurantsRepository();
         repository.Insert(restaurant);
         return(RedirectToAction("Index"));
     }
 }
        public IActionResult Create()
        {
            RestaurantCreateViewModel model = new RestaurantCreateViewModel(context);

            return(View(model));
        }
Ejemplo n.º 14
0
 public void TestInitialize()
 {
     _restaurantCreateViewModel = _fixture.Create <RestaurantCreateViewModel>();
     _validator = new RestaurantCreateViewModelValidator();
 }