// GET: Reservations/Create
        public async Task<ActionResult> Create(int id)
        {
            var vacationProperty = await _vacationPropertiesRepository.FindAsync(id);
            var reservation = new ReservationViewModel
            {
                ImageUrl = vacationProperty.ImageUrl,
                Description = vacationProperty.Description,
                VacationPropertyId = vacationProperty.Id,
                VacationPropertyDescription = vacationProperty.Description,
                UserName = vacationProperty.User.Name,
                UserPhoneNumber = vacationProperty.User.PhoneNumber,
            };

            return View(reservation);
        }
        public void GivenACreateAction_WhenTheModelStateIsInalid_ThenRenderTheDefaultView()
        {
            var model = new ReservationViewModel();
            var stubVacationPropertiesRepository = Mock.Of<IVacationPropertiesRepository>();
            var stubReservationsRepository = Mock.Of<IReservationsRepository>();
            var stubUsersRepository = Mock.Of<IUsersRepository>();
            var stubNotifier = Mock.Of<INotifier>();

            var controller = new ReservationsController(
                stubVacationPropertiesRepository, stubReservationsRepository, stubUsersRepository, stubNotifier);
            controller.ModelState.AddModelError("Message", "The Message field is required");

            controller.WithCallTo(c => c.Create(model))
                .ShouldRenderDefaultView();
        }
        public void GivenACreateAction_WhenTheModelStateIsValid_ThenItRedirectsToVacationPropertiesIndex()
        {
            var model = new ReservationViewModel();

            var stubVacationPropertiesRepository = Mock.Of<IVacationPropertiesRepository>();
            var mockReservationsRepository = new Mock<IReservationsRepository>();
            var stubUsersRepository = Mock.Of<IUsersRepository>();
            var mockNotifier = new Mock<INotifier>();

            var controller = new ReservationsController(
                stubVacationPropertiesRepository, mockReservationsRepository.Object, stubUsersRepository,
                mockNotifier.Object);

            controller.WithCallTo(c => c.Create(model))
                .ShouldRedirectTo<VacationPropertiesController>(c => c.Index());

            mockReservationsRepository.Verify(r => r.CreateAsync(It.IsAny<Reservation>()), Times.Once);
            mockNotifier.Verify(n => n.SendNotificationAsync(It.IsAny<Reservation>()), Times.Once());
        }
        public async Task<ActionResult> Create(ReservationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var reservation = new Reservation
                {
                    Message = model.Message,
                    PhoneNumber = model.UserPhoneNumber,
                    Name = model.UserName,
                    VactionPropertyId = model.VacationPropertyId,
                    Status = ReservationStatus.Pending,
                    CreatedAt = DateTime.Now
                };

                await _reservationsRepository.CreateAsync(reservation);
                reservation.VacationProperty = new VacationProperty {Description = model.VacationPropertyDescription};
                await _notifier.SendNotificationAsync(reservation);

                return RedirectToAction("Index", "VacationProperties");
            }

            return View(model);
        }