Exemplo n.º 1
0
        public ActionResult AddComment(string country, string city, int guestnumber = 0, int bednumber = 0, DateTime?bookfrom = null, DateTime?bookto = null, string type = "Hotel", int id = 0, string text = "")
        {
            ApplicationUser user   = repository.GetUserById(GetUserId());
            bool            Succes = false;

            if (type == "Hotel")
            {
                Hotel hotel = repository.GetHotelByID(id);
                Succes = repository.AddComment(null, hotel, user, text);
            }
            else
            {
                Resort resort = repository.GetResortByID(id);
                Succes = repository.AddComment(resort, null, user, text);
            }


            if (Succes)
            {
                FiltrResortHotel filtrclass = filtr;
                filtrclass.Country     = country;
                filtrclass.City        = city;
                filtrclass.GuestNumber = guestnumber;
                filtrclass.BedNumber   = bednumber;
                filtrclass.BookFrom    = bookfrom == null ? DateTime.MinValue : (DateTime)bookfrom;
                filtrclass.BookTo      = bookto == null ? DateTime.MinValue : (DateTime)bookto;



                filtrclass.Filtr();


                SearchModelViewResortHotel viewmodel = new SearchModelViewResortHotel();
                viewmodel.Hotels  = filtrclass.Hotels;
                viewmodel.Resorts = filtrclass.Resorts;
                viewmodel.ResortListOfHolidayHomes = filtrclass.ResortListOfHolidayHomes;
                viewmodel.ResortListOfRooms        = filtrclass.ResortListOfRooms;
                viewmodel.HotelListOfRooms         = filtrclass.HotelListOfRooms;



                return(View("FiltrResortHotel", viewmodel));
            }
            else
            {
                return(View("Error"));
            }
        }
        public void when_calling_AddComment_returns_view_FiltrResortHotel()
        {
            Mock <IHolidaysRepository> mock = new Mock <IHolidaysRepository>();

            mock.Setup(x => x.GetUserById(It.IsAny <string>())).Returns(new ApplicationUser()
            {
                UserName = "******", Id = "aaa-bbb-ccc"
            });

            List <Hotel> listHotel = new List <Hotel>()
            {
                new Hotel()
                {
                    Name = "Hotel Kraków", City = "Kraków", Country = "Poland", TelephoneNumber = 777888666
                }
            };

            Mock <FiltrResortHotel> mockAbstract = new Mock <FiltrResortHotel>();

            mockAbstract.Setup(x => x.Hotels).Returns(listHotel);

            mock.Setup(x => x.GetHotelByID(It.IsAny <int>())).Returns(new Hotel()
            {
                Name = "Hotel Kraków", City = "Kraków", Country = "Poland", TelephoneNumber = 777888666
            });
            mock.Setup(x => x.GetResortByID(It.IsAny <int>())).Returns(new Resort()
            {
                Name = "Resort Władysławowo", City = "Władysławowo", Country = "Poland", TelephoneNumber = 794219756
            });
            mock.Setup(x => x.AddComment(null, It.IsAny <Hotel>(), It.IsAny <ApplicationUser>(), It.IsAny <string>())).Returns(true);
            HomeController controller = new HomeController(mock.Object, () => "aaa-bbb-ddd", mockAbstract.Object);



            ViewResult result = ((ViewResult)controller.AddComment("Poland", "Kraków", 1, 2, new DateTime(2019, 8, 25), new DateTime(2019, 8, 25), "Hotel", 1, "text"));


            Assert.AreEqual(result.ViewName, "FiltrResortHotel");

            SearchModelViewResortHotel model = (SearchModelViewResortHotel)result.Model;

            Assert.AreEqual(model.Hotels.First().City, "Kraków");
        }
Exemplo n.º 3
0
        public ActionResult FiltrResortHotel(string country, string city, int guestnumber = 0, int bednumber = 0, DateTime?bookfrom = null, DateTime?bookto = null)
        {
            if (string.IsNullOrEmpty(country))
            {
                ModelState.AddModelError("country", "Country is Required");
            }

            if (string.IsNullOrEmpty(city))
            {
                ModelState.AddModelError("city", "City is Required");
            }


            if (bookfrom > bookto)
            {
                ModelState.AddModelError("bookfrom", "Book From is Later than Book To");
            }

            if (bookfrom == bookto && bookto != null)
            {
                ModelState.AddModelError("bookfrom", "Book From is equal Book To");
            }


            if (bookfrom <= DateTime.Now)
            {
                ModelState.AddModelError("bookfrom", "Book From should be later than today");
            }

            if (bookto <= DateTime.Now)
            {
                ModelState.AddModelError("bookto", "Book to should be later than today");
            }



            FiltrResortHotel filtrclass = filtr;

            filtrclass.Country     = country;
            filtrclass.City        = city;
            filtrclass.GuestNumber = guestnumber;
            filtrclass.BedNumber   = bednumber;
            filtrclass.BookFrom    = bookfrom == null ? DateTime.MinValue : (DateTime)bookfrom;
            filtrclass.BookTo      = bookto == null ? DateTime.MinValue : (DateTime)bookto;



            filtrclass.Filtr();


            SearchModelViewResortHotel viewmodel = new SearchModelViewResortHotel();

            viewmodel.Hotels  = filtrclass.Hotels;
            viewmodel.Resorts = filtrclass.Resorts;
            viewmodel.ResortListOfHolidayHomes = filtrclass.ResortListOfHolidayHomes;
            viewmodel.ResortListOfRooms        = filtrclass.ResortListOfRooms;
            viewmodel.HotelListOfRooms         = filtrclass.HotelListOfRooms;



            return(View("FiltrResortHotel", viewmodel));
        }