/// <summary>
        /// Creates a new reservation and saves it to the database
        /// </summary>
        /// <param name="request">Create reservation DTO</param>
        /// <returns>The newly created reserrvation DTO</returns>
        public Dto.ReservationResult AddNewReservation(Dto.ReservationRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            return(Call(() =>
            {
                //creates a new reservation entity
                var reservation = ReservationFactory.CreateReservation(request.Name, request.ReservationDateTime, request.GuestsCount, request.UserId);

                var entityValidator = EntityValidatorLocator.CreateValidator();
                if (entityValidator.IsValid(reservation))
                {
                    using (var transaction = _reservationRepository.BeginTransaction())
                    {
                        _reservationRepository.Add(reservation);
                        transaction.Commit();
                    }
                }
                else
                {
                    return new Dto.ReservationResult
                    {
                        Status = ActionResultCode.Errored,
                        Message = Messages.validation_errors,
                        Errors = entityValidator.GetInvalidMessages(reservation)
                    };
                }

                //returns success
                return reservation.ProjectedAs <Dto.ReservationResult>();
            }));
        }
        private void checkInBtn_Click(object sender, RoutedEventArgs e)
        {
            int      roomID;
            string   customerCardID = customerCardIDTxt.Text.Trim();
            string   roomIDStr      = roomIDTxt.Text.Trim();
            DateTime?checkInDate    = checkInDatepicker.SelectedDate;
            DateTime?checkOutDate   = checkOutDatepicker.SelectedDate;

            bool success = int.TryParse(roomIDStr, out roomID);

            MessageBox.Show(DateTime.Now.Hour.ToString());
            if (!success)
            {
                errorLbl.Text = "Room ID must be a number";
            }
            else if (DateTime.Now.Hour <= 10)
            {
                errorLbl.Text = "Check in time is 10 AM";
            }
            else if (customerCardID == "" || !checkInDate.HasValue || !checkOutDate.HasValue)
            {
                errorLbl.Text = "Please input all field!";
            }
            else
            {
                RoomMediator rmediator = new RoomMediator();
                Room         room      = rmediator.getRoom(roomID);
                if (room == null || room.status == "Not Available")
                {
                    errorLbl.Text = "Room is not available";
                }
                else
                {
                    CustomerMediator cmediator = new CustomerMediator();
                    Customer         customer  = cmediator.getCustomer(customerCardID);
                    if (customer == null)
                    {
                        showField();
                        errorLbl.Text = "Please register customer!";
                    }
                    else
                    {
                        ReservationMediator mediator    = new ReservationMediator();
                        ReservationFactory  factory     = new ReservationFactory();
                        Reservation         reservation = mediator.addReservation(factory.createNewReservation(customer.customerID, roomID, checkInDate, checkOutDate));
                        room.status        = "Not Available";
                        room               = rmediator.updateRoom(roomID, room);
                        totalPriceTxt.Text = "Total Price = Rp. " + room.price;
                        if (reservation == null)
                        {
                            MessageBox.Show("Reservation failed!");
                        }
                        else
                        {
                            MessageBox.Show("Reservation success!");
                        }
                    }
                }
            }
        }
        private void btnTestReservations_Click(object sender, EventArgs e)
        {
            ReservationFactory factory = ReservationFactory.getFactoryInstance();

            factory.reserveRoomsTest();
            lblStatus.Text = "reservation.xml Created";
            factory.createReservationFile();
        }
 public ListenerForm(String id, String HotelName, ReservationFactory subject)
 {
     InitializeComponent();
     this.hotelID   = id;
     this.hotelName = HotelName;
     this.subject   = subject;
     subject.RegisterObserver(this);
     lblStatus.Text = hotelName + " (" + hotelID + ")";
 }
Exemple #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Membre membre = Session[TP3.SESSIONMEMBRE] as Membre;

            if (membre != null)
            {
                Reservation[] reservations = ReservationFactory.GetAllById(System.Configuration.ConfigurationManager.ConnectionStrings["cnnStr"].ConnectionString, membre.Id);
                Repeater_Voyages.DataSource = reservations.ToArray();
                Repeater_Voyages.DataBind();
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
Exemple #6
0
 protected void btnReserver_Click(object sender, EventArgs e)
 {
     if (voyage.NbPassagers >= int.Parse(txtReserve.Text))
     {
         int passager = voyage.NbPassagers - int.Parse(txtReserve.Text);
         VoyageFactory.UpdatePassager(System.Configuration.ConfigurationManager.ConnectionStrings["cnnStr"].ConnectionString, passager, ID);
         Reservation reservation = new Reservation(0, membre.Id, ID, int.Parse(txtReserve.Text));
         ReservationFactory.Save(System.Configuration.ConfigurationManager.ConnectionStrings["cnnStr"].ConnectionString, reservation);
         Response.Redirect("SearchTrips.aspx");
     }
     else
     {
         NotEnoughPlace.Visible = true;
     }
 }
Exemple #7
0
        public bool add(int employeeId, int visitorId, int roomId, string checkIn, int night, int totalPrice)
        {
            Reservation r = ReservationFactory.create(employeeId, visitorId, roomId, checkIn, night, totalPrice);

            var room = RoomController.getInstance().find(roomId);

            if (room.Status == "Booked")
            {
                return(false);
            }

            RoomController.getInstance().update(roomId);
            ReservationRepository.add(r);
            return(true);
        }
Exemple #8
0
        public void CanViewVipCustomers()
        {
            // arrange
            IRepo <Customer>     customerRepo     = new MockContext <Customer>();
            IRepo <Car>          carRepo          = new MockContext <Car>();
            IRepo <Reservation>  reservationRepo  = new MockContext <Reservation>();
            IRepo <Location>     locationRepo     = new MockContext <Location>();
            IRepo <Model>        modelRepo        = new MockContext <Model>();
            IRepo <Manufacturer> manufacturerRepo = new MockContext <Manufacturer>();

            var customerFactory    = new CustomerFactory();
            var reservationFactory = new ReservationFactory();

            customerRepo.Insert(customerFactory.GetCustomer(1, 1, "1"));
            customerRepo.Insert(customerFactory.GetCustomer(2, 2, "2"));
            customerRepo.Insert(customerFactory.GetCustomer(3, 3, "3"));

            reservationRepo.Insert(reservationFactory.GetReservation(1, 1, 3, new DateTime(2019, 8, 29), new DateTime(2020, 8, 31)));
            reservationRepo.Insert(reservationFactory.GetReservation(2, 22, 3, new DateTime(2020, 8, 29), new DateTime(2020, 8, 31)));
            reservationRepo.Insert(reservationFactory.GetReservation(3, 2, 3, new DateTime(2020, 8, 29), new DateTime(2020, 8, 31)));
            reservationRepo.Insert(reservationFactory.GetReservation(4, 3, 3, new DateTime(2020, 8, 29), new DateTime(2020, 8, 31)));
            reservationRepo.Insert(reservationFactory.GetReservation(5, 4, 3, new DateTime(2020, 8, 29), new DateTime(2020, 8, 31)));
            reservationRepo.Insert(reservationFactory.GetReservation(6, 4, 2, new DateTime(2020, 8, 29), new DateTime(2020, 8, 31)));
            reservationRepo.Insert(reservationFactory.GetReservation(7, 5, 2, new DateTime(2020, 8, 29), new DateTime(2020, 8, 31)));
            reservationRepo.Insert(reservationFactory.GetReservation(8, 4, 1, new DateTime(2020, 8, 29), new DateTime(2020, 8, 31)));

            var viewModel = new CustomerViewModel();

            var controller = new CustomerController(carRepo, customerRepo, reservationRepo,
                                                    locationRepo, modelRepo, manufacturerRepo);

            // act
            controller.VipCustomersList(viewModel, "Status desc");
            IEnumerable <QueryCustomer> customers = viewModel.Customers;

            // assert
            Assert.IsNotNull(customers);
            Assert.AreEqual(2, customers.Count());
            Assert.AreEqual("2", customers.ElementAt(0).Name);
            Assert.AreEqual("3", customers.ElementAt(1).Name);
            Assert.AreEqual(4, customers.ElementAt(1).ReservationsCount);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int ID = 0;

            if (Request.QueryString["ID"] != null)
            {
                ID = int.Parse(Request.QueryString["ID"]);
            }
            else
            {
                Response.Redirect("SearchTrips.aspx");
            }
            Reservation reservation = ReservationFactory.GetByID(ConfigurationManager.ConnectionStrings["cnnStr"].ConnectionString, ID);
            Voyage      voyage      = VoyageFactory.GetByID(ConfigurationManager.ConnectionStrings["cnnStr"].ConnectionString, reservation.IdVoyage);
            int         nbPassager  = voyage.NbPassagers + reservation.NbPassager;

            VoyageFactory.UpdatePassager(ConfigurationManager.ConnectionStrings["cnnStr"].ConnectionString, nbPassager, reservation.IdVoyage);
            ReservationFactory.Delete(ConfigurationManager.ConnectionStrings["cnnStr"].ConnectionString, ID);
            Response.Redirect("SearchTrips.aspx");
        }
Exemple #10
0
        public async Task Add(Guid reservationId, Guid userId, ReservationOffer request)
        {
            var offer = await _reservationsQuerier.GetReservationOffer(request.OfferRequest);

            if (!offer.Equals(request))
            {
                throw new Exception("Offer has expired.");
            }

            if (AnyPlaceIsInvalid(request.OfferRequest.Places))
            {
                throw new Exception("Invalid place configuration.");
            }

            Show show = await _ctx.Shows.Include(s => s.Reservations).FirstOrDefaultAsync(s => s.Id == request.OfferRequest.ShowId);

            if (show is null)
            {
                throw new KeyNotFoundException(nameof(request.OfferRequest.ShowId));
            }

            User user = await _ctx.Users.FindAsync(userId);

            if (user is null)
            {
                throw new KeyNotFoundException(nameof(userId));
            }

            Reservation reservation = ReservationFactory.Create(reservationId, user);

            AddPlacesToReservation(request.OfferRequest.Places, reservation);
            show.AddReservation(reservation);

            await _ctx.SaveChangesAsync();

            _emailSender.Send(new Email()); //TODO
        }
Exemple #11
0
        public async Task <ReservationDTO> AddReservation(ReservationDTO model, string operatorId)
        {
            ReservationDTO result = null;

            var service  = _serviceRepository.Get(model.ServiceId);
            var servicer = _servicerRepository.Get(model.ServicerId);

            if (service == null && servicer == null)
            {
                throw new Exception("异常预约!");
            }

            if (service.ServeScope > 0)
            {
                var res = await _amapProxy.Geo(model?.ServiceDestination?.StreetAddress);

                if (res == null)
                {
                    throw new Exception("地址异常!");
                }

                var sres = await _amapProxy.Geo(service.StreetAddress);

                if (sres != null)
                {
                    var distance = GetDistance(res.Longitude, res.Latitude, sres.Longitude, sres.Latitude);
                    if (distance > service.ServeScope)
                    {
                        throw new Exception("超出范围!");
                    }
                }
            }

            var reservation = ReservationFactory.CreateInstance(
                service,
                servicer,
                model.ServiceDestination,
                model.CustomerName,
                model.CustomerMobile,
                model.AppointTime,
                service.SincerityGold,
                operatorId);

            _reservationRepository.Add(reservation);
            _dbUnitOfWork.Commit();

            #region create order
            var orderItems = new List <OrderItemDTO>();

            orderItems.Add(new OrderItemDTO
            {
                Count              = 1,
                ObjectId           = reservation.Id,
                ObjectNo           = reservation.ReservationNo,
                Title              = reservation.Service?.Title ?? "",
                TradeUnitPrice     = reservation.SincerityGoldNeedToPay,
                SelectedProperties = string.Empty,
                PreviewPictureUrl  = string.Empty
            });

            await _orderServiceProxy.CreateOrder(new Proxies.DTOs.OrderDTO
            {
                CreatedBy          = reservation.CreatedBy,
                CustomerAddress    = reservation.ServiceDestination,
                CustomerMobile     = reservation.CustomerMobile,
                CustomerName       = reservation.CustomerName,
                InvoiceType        = InvoiceType.None,
                PayAmount          = orderItems.Sum(o => o.TradeUnitPrice *o.Count),
                PreferentialAmount = 0,
                ShippingCost       = 0,
                Tax            = 0,
                TotalAmount    = reservation.SincerityGoldNeedToPay,
                OrderItems     = orderItems,
                Mark           = "Reservation",
                Invoiceremark  = "",
                Remark         = $"预约时间:{reservation?.AppointTime},预约服务:{reservation?.Service?.Title},服务者:{reservation?.Servicer?.Name ?? "未指定"}",
                OrganizationId = reservation.OrganizationId
            });

            #endregion

            reservation.ConfirmAppoint();
            _eventBus.Commit();

            return(new ReservationDTO
            {
                AppointTime = reservation.AppointTime,
                CustomerMobile = reservation.CustomerMobile,
                CustomerName = reservation.CustomerName,
                Id = reservation.Id,
                ReservationNo = reservation.ReservationNo,
                ServiceDestination = reservation.ServiceDestination,
                ServiceId = reservation.ServiceId,
                ServicerId = reservation.ServicerId,
                SincerityGoldNeedToPay = reservation.SincerityGoldNeedToPay,
                Status = reservation.Status,
                OrganizationId = reservation.OrganizationId,
                OrderId = reservation.OrderId
            });
        }
 private void FlightRequestForm_Load(object sender, EventArgs e)
 {
    reservationFactory = new ReservationFactory();
    flightRequestList = new List<FlightRequest>();
 }
 private object ReservationAdded(object reservation)
 {
     return(ReservationFactory.Add(reservation));
 }
 public object Get(string id)
 {
     return(ReservationFactory.Get(id));
 }
Exemple #15
0
 public object Add(object reservation)
 {
     return(ReservationFactory.Add(reservation));
 }