Exemple #1
0
        public async Task TestCreateReservation(bool isMember, string userId)
        {
            if (isMember)
            {
                _reservation.Email     = "*****@*****.**";
                _reservation.Mobile    = "0400000000";
                _reservation.GuestName = "default";
            }
            try
            {
                var deleteQuery = "delete from ReservationRequests";
                RemoteQueryDatabase(deleteQuery);
                await _service.CreateReservation(_reservation, userId);

                var selectQuery = $"select * from ReservationRequests";
                var record      = RemoteQueryDatabase(selectQuery);
                ValidateResults(record, new List <ReservationRequest> {
                    _reservation
                });
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                throw new Exception(ex.InnerException.Message);
            }
        }
        //verifies the information and applies if it works.
        private void btnAddReservation_Click(object sender, EventArgs e)
        {
            // Double checking fields before creating the reservations.
            if (string.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("Please enter a reserver name", "Missing information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (string.IsNullOrEmpty(txtPhone.Text) || System.Text.RegularExpressions.Regex.IsMatch(txtPhone.Text, "[^0-9]"))
            {
                MessageBox.Show("Please enter a proper phone number", "Missing information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (cmbHour.SelectedIndex < 0 || cmbMinute.SelectedIndex < 0)
            {
                MessageBox.Show("Please pick a time", "Missing information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // database needed this in a string format.
                string reservationDate = monthCalendar1.SelectionStart.Year.ToString() + "-"
                                         + monthCalendar1.SelectionStart.Month.ToString("00") + "-"
                                         + monthCalendar1.SelectionStart.Day.ToString("00") + " " + cmbHour.SelectedItem.ToString() + ":" + cmbMinute.SelectedItem.ToString() + ":" + "00";

                reservationService.CreateReservation(CurrentTable.TableNumber, reservationDate, long.Parse(txtPhone.Text), txtName.Text);
                MessageBox.Show("Reservation is created", "Reservation status", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
        }
Exemple #3
0
        public async Task <IActionResult> ReserveByRoomType(int roomTypeId, ReservationModel model)
        {
            var reservation = await _reservationService.CreateReservation(
                roomTypeId, model.Start, model.End, model.Name, model.Email, model.Message, model.PhoneCountry,
                model.Phone, model.NumberOfGuests);

            return(Ok(new
            {
                reservationId = reservation.Id
            }));
        }
Exemple #4
0
        public IHttpActionResult PostReservation(ReservationPostModel reservationPostModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var createdReservation = reservationService.CreateReservation(reservationPostModel);

            return(CreatedAtRoute("DefaultApi", new { id = createdReservation.Id }, createdReservation));
        }
Exemple #5
0
        public ReservationServiceTests()
        {
            service = new ReservationService();

            service.CreateCampsite(new Campsite()
            {
                Id = 1, Name = "Cozy Cabin"
            });
            service.CreateCampsite(new Campsite()
            {
                Id = 2, Name = "Tent"
            });
            service.CreateCampsite(new Campsite()
            {
                Id = 3, Name = "Shoe"
            });
            service.CreateCampsite(new Campsite()
            {
                Id = 4, Name = "Hovel"
            });

            service.CreateReservation(new Reservation()
            {
                StartDate = new DateTime(4.Days().Ticks), EndDate = new DateTime(5.Days().Ticks), CampsiteId = 1
            });
            service.CreateReservation(new Reservation()
            {
                StartDate = new DateTime(12.Days().Ticks), EndDate = new DateTime(15.Days().Ticks), CampsiteId = 2
            });
            service.CreateReservation(new Reservation()
            {
                StartDate = new DateTime(4.Days().Ticks), EndDate = new DateTime(5.Days().Ticks), CampsiteId = 3
            });
            service.CreateReservation(new Reservation()
            {
                StartDate = new DateTime(4.Days().Ticks), EndDate = new DateTime(5.Days().Ticks), CampsiteId = 4
            });
        }
Exemple #6
0
        public void CanCreateOnlyUniqueReservations(int startDate, int endDate, int campsiteId, bool canCreate)
        {
            // Setup
            var reservation = new Reservation()
            {
                CampsiteId = campsiteId,
                StartDate  = new DateTime(startDate.Days().Ticks),
                EndDate    = new DateTime(endDate.Days().Ticks),
            };

            // Test
            var success = service.CreateReservation(reservation);

            // Assert
            Assert.Equal(success, canCreate);
        }
        public async Task <IActionResult> Create(ReservationRequest reservation)
        {
            if (ModelState.IsValid)
            {
                var isVaildReservation = await _service.IsValidReservation(reservation);

                if (!isVaildReservation)
                {
                    ViewBag.AvailableTimeMsg = "Sorry, the reservation end time is outside the sitting period";
                    return(View(reservation));
                }
                var user = await _userManager.FindByEmailAsync(User.Identity.Name);

                var userId    = user?.Id;
                var isSuccess = await _service.CreateReservation(reservation, userId);

                if (isSuccess)
                {
                    return(RedirectToAction(nameof(Success), reservation));
                }
                else
                {
                    var availableTimeRange = await _service.GetAvailableTimeRange(reservation);

                    if (availableTimeRange == null)
                    {
                        ViewBag.AvailableTimeMsg = "Sorry, there is no available time on selected date, please select another date";
                    }
                    else
                    {
                        var startTime = availableTimeRange[0];
                        ViewBag.AvailableTimeMsg =
                            $"There is no vacancy on selected time, please select {reservation.StartDateTime.ToString("yyyy-MM-dd")} {startTime}";
                    }
                    return(View(reservation));
                }
            }
            return(View(reservation));
        }
Exemple #8
0
        // Method for Register New Car Rent Screen logic
        public void RegisterNewCarRent()
        {
            Console.Clear();

            Car car = new Car();
            PrintColorMessage  printColorMessage   = new PrintColorMessage();
            ReservationService reservationServices = new ReservationService();
            Customer           customer            = new Customer();
            Reservation        reservation         = new Reservation();
            Navigation         navigation          = new Navigation();

            Console.Write("Car Plate: ");
            reservation.CarPlate = Console.ReadLine();

            Console.Write("Car ID: ");
            reservation.CarID = Convert.ToInt32(Console.ReadLine());

            Console.Write("Customer ID: ");
            reservation.CustomerID = Convert.ToInt32(Console.ReadLine());

            reservation.ReservStatsID = 1;

            Console.Write("Start Date: ");
            reservation.StartDate = Convert.ToDateTime(Console.ReadLine());

            Console.Write("End Date: ");
            var endDate = Console.ReadLine();

            reservation.EndDate = Convert.ToDateTime(endDate);

            Console.Write("Location: ");
            reservation.Location = Console.ReadLine();

            reservationServices.CreateReservation(reservation);

            navigation.GoToMenu();
        }
        public ActionResult CustomerInfo(string firstName, string lastName, string phone, string sport, string email)
        {
            var customer = new Customer();
            customer.FirstName = firstName;
            customer.LastName = lastName;
            customer.Sport = sport;
            customer.Email = email;
            customer.Phone = phone;

            var cart = GetCart();

            if (_reservations.IsSlotInCartAlreadyTaken(cart))
            {
                DeleteCart();
                TempData["InvalidCart"] = "Invalid";
                return RedirectToAction("Index");
            }

            var reservation = _reservations.CreateReservation(cart, customer);

            TempData["Reservation"] = reservation;

            return RedirectToAction("confirm");
        }
Exemple #10
0
 public async Task <bool> PostReservation([FromBody] Reservation reservation)
 {
     return(await _reservationService.CreateReservation(reservation));
 }
        public void ReservationService_CreateReservation_ReturnsCreatedReservation()
        {
            //Arrange

            Projection projection = new Projection
            {
                Id           = Guid.NewGuid(),
                AuditoriumId = 1,
                DateTime     = DateTime.Now.AddHours(5),
                MovieId      = Guid.NewGuid()
            };
            SeatResultModel srm1 = new SeatResultModel
            {
                ErrorMessage    = null,
                IsSuccessful    = true,
                SeatDomainModel = new SeatDomainModel
                {
                    Id           = Guid.NewGuid(),
                    AuditoriumId = 1,
                    Number       = 1,
                    Row          = 1
                }
            };
            SeatResultModel srm2 = new SeatResultModel
            {
                ErrorMessage    = null,
                IsSuccessful    = true,
                SeatDomainModel = new SeatDomainModel
                {
                    Id           = Guid.NewGuid(),
                    AuditoriumId = 1,
                    Number       = 2,
                    Row          = 1
                }
            };
            List <SeatResultModel> seatResults = new List <SeatResultModel>();

            Seat s1 = new Seat
            {
                Id           = srm1.SeatDomainModel.Id,
                AuditoriumId = srm1.SeatDomainModel.AuditoriumId,
                Number       = srm1.SeatDomainModel.Number,
                Row          = srm1.SeatDomainModel.Row
            };
            Seat s2 = new Seat
            {
                Id           = srm2.SeatDomainModel.Id,
                AuditoriumId = srm2.SeatDomainModel.AuditoriumId,
                Number       = srm2.SeatDomainModel.Number,
                Row          = srm2.SeatDomainModel.Row
            };
            List <Seat> seats = new List <Seat>();

            seats.Add(s1);
            seats.Add(s2);
            CreateReservationModel reservation = new CreateReservationModel
            {
                ProjectionId = projection.Id,
                UserId       = Guid.NewGuid(),
                SeatIds      = seats.Select(s => new SeatDomainModel
                {
                    Id           = s.Id,
                    AuditoriumId = s.AuditoriumId,
                    Number       = s.Number,
                    Row          = s.Row
                })
            };
            //TO BE CONTINUED.

            Reservation reservation2 = new Reservation
            {
                Id               = Guid.NewGuid(),
                ProjectionId     = reservation.ProjectionId,
                UserId           = reservation.UserId,
                ReservationSeats = new List <ReservationSeat>()
            };
            ReservationSeat rs1 = new ReservationSeat
            {
                SeatId        = s1.Id,
                Seat          = s1,
                ReservationId = Guid.NewGuid(),
                Reservation   = reservation2
            };

            reservation2.ReservationSeats.Add(rs1);

            _mockReservationService.Setup(x => x.GetTakenSeats(It.IsAny <Guid>())).Returns(seatResults);
            _mockSeatRepository.Setup(x => x.GetAll()).ReturnsAsync(seats);
            _mockProjectionRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(projection);
            _mockSeatRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(s1);
            _mockReservationRepository.Setup(x => x.Insert(It.IsAny <Reservation>())).Returns(reservation2);

            //Assert
            var resultAction = _reservationService.CreateReservation(reservation);

            //Act
            Assert.IsNotNull(resultAction);
        }