Example #1
0
        public IActionResult CreateAccommodation(AccommodationModelIn newAccommodation)
        {
            var accommodation = newAccommodation.FromModelInToAccommodation();
            var response      = this.accommodationLogic.AddAccommodation(accommodation);

            return(Ok(new AccommodationModelOut(response, (0, new List <Review>()))));
        }
        public IActionResult Get()
        {
            var queryString = HttpUtility.ParseQueryString(this.HttpContext.Request.QueryString.Value);

            if (queryString.Count == 0)
            {
                List <AccommodationQueryOut> accommodations         = this.accommodationLogic.GetAll();
                List <AccommodationModelOut> accommodationsToReturn = new List <AccommodationModelOut>();
                foreach (var item in accommodations)
                {
                    AccommodationModelOut a = new AccommodationModelOut(item);
                    accommodationsToReturn.Add(a);
                }
                return(Ok(accommodationsToReturn));
            }
            else
            {
                try
                {
                    AccommodationModelIn accommodationModelIn = new AccommodationModelIn
                    {
                        TouristSpotName = queryString.Get("touristSpotName"),
                        CheckIn         = new DateTime(
                            Int32.Parse(queryString.Get("checkInYear")),
                            Int32.Parse(queryString.Get("checkInMonth")),
                            Int32.Parse(queryString.Get("checkInDay"))
                            ),
                        CheckOut = new DateTime(
                            Int32.Parse(queryString.Get("checkOutYear")),
                            Int32.Parse(queryString.Get("checkOutMonth")),
                            Int32.Parse(queryString.Get("checkOutDay"))
                            ),
                        TotalGuests = Int32.Parse(queryString.Get("totalGuests")),
                        Babies      = Int32.Parse(queryString.Get("babies")),
                        Kids        = Int32.Parse(queryString.Get("kids")),
                        Adults      = Int32.Parse(queryString.Get("adults")),
                        Retirees    = Int32.Parse(queryString.Get("retirees"))
                    };
                    int tot = accommodationModelIn.Babies + accommodationModelIn.Kids
                              + accommodationModelIn.Adults + accommodationModelIn.Retirees;
                    if (accommodationModelIn.TotalGuests != tot)
                    {
                        return(BadRequest("Wrong input: the number of hosts is incorrect."));
                    }
                    AccommodationQueryIn         accommodationQueryIn   = new AccommodationQueryIn(accommodationModelIn);
                    List <AccommodationQueryOut> accommodations         = this.accommodationLogic.GetByTouristSpot(accommodationQueryIn);
                    List <AccommodationModelOut> accommodationsToReturn = new List <AccommodationModelOut>();
                    foreach (var item in accommodations)
                    {
                        AccommodationModelOut a = new AccommodationModelOut(item);
                        accommodationsToReturn.Add(a);
                    }
                    return(Ok(accommodationsToReturn));
                }
                catch (Exception e)
                {
                    return(BadRequest("Wrong input: incorrect query string"));
                }
            }
        }
Example #3
0
 public AccommodationQueryIn(AccommodationModelIn accommodationModelIn)
 {
     this.TouristSpotName = accommodationModelIn.TouristSpotName;
     this.CheckIn         = accommodationModelIn.CheckIn;
     this.CheckOut        = accommodationModelIn.CheckOut;
     this.TotalGuests     = accommodationModelIn.TotalGuests;
     this.Babies          = accommodationModelIn.Babies;
     this.Kids            = accommodationModelIn.Kids;
     this.Adults          = accommodationModelIn.Adults;
     this.Retirees        = accommodationModelIn.Retirees;
 }
Example #4
0
        public void TestCreateAccommodationOK()
        {
            Accommodation accommodation = new Accommodation()
            {
                Name          = "abm",
                SpotId        = 1,
                Address       = "a",
                ContactNumber = "a",
                Information   = "a",
                PricePerNight = 5.0,
                Id            = 1,
                Images        = new List <AccommodationImage>(),
                Full          = false
            };

            string[] image = new string[1];
            image[0] = "h";
            AccommodationModelIn accommodationModel = new AccommodationModelIn()
            {
                Address     = accommodation.Address,
                Contact     = accommodation.ContactNumber,
                Name        = accommodation.Name,
                Information = accommodation.Information,
                Price       = accommodation.PricePerNight,
                SpotId      = accommodation.SpotId,
                Images      = image
            };
            var mockAccommodation = new Mock <IAccommodationLogic>(MockBehavior.Strict);

            mockAccommodation.Setup(p => p.AddAccommodation(It.IsAny <Accommodation>())).Returns(accommodation);
            var controller = new AccommodationController(mockAccommodation.Object);

            var result = controller.CreateAccommodation(accommodationModel) as OkObjectResult;

            mockAccommodation.VerifyAll();
            Assert.AreEqual(200, result.StatusCode);
        }