public async Task CreatePendingBookingForOneSeat()
        {
            // Arrange
            using (var context = DbContextHelper.GetInMemoryDbContext())
            {
                var  service        = new BookingService(context);
                Guid id             = Guid.NewGuid();
                var  pendingBooking = new PendingBooking()
                {
                    Id                      = id,
                    Date                    = DateTime.Now,
                    EvenScheduleId          = _seedService.EvenSchedules.First().Id,
                    ExpirationDate          = DateTime.Now.AddMinutes(2),
                    PendingBookingPositions = new List <PendingBookingPosition>
                    {
                        new PendingBookingPosition
                        {
                            PendingBookingId       = id,
                            ServicePlacePositionId = _seedService.ServicePlacePositions[0].Id
                        }
                    }
                };
                int expectedSeat = 1;

                // Act
                var pendingBookingFromDb = await service.CreatePendingBookingAsync(pendingBooking);

                // Assert
                Assert.True(pendingBookingFromDb.PendingBookingPositions.Count == expectedSeat);
            }
        }
Exemple #2
0
        /// <summary>
        /// Create/ Send messages to MSMQ
        /// </summary>
        public void SendPendingMessage(PendingBooking pb, UpdatedBooking ub, BlockBooking bb)
        {
            //int start = 0;
            int     maxNumberofqueues = queueLists.Count - 1;
            Message message           = new Message();

            message.Recoverable = true;
            if (pb != null)
            {
                message.Body  = pb;
                message.Label = "pending";
            }
            else if (ub != null)
            {
                message.Body  = ub;
                message.Label = "update";
            }
            else if (bb != null)
            {
                message.Body  = bb;
                message.Label = "blockbooking";
            }
            mq = queueLists[bookingCounter];
            logger.Debug("message sending to " + mq.Path);
            logger.Debug("message: " + message.ToString());
            mq.Send(message);
            if (bookingCounter == maxNumberofqueues)
            {
                bookingCounter = 0;
            }
            else
            {
                bookingCounter++;
            }
        }
Exemple #3
0
        private async Task <Customer> UpdateCustomer(PendingBooking pendingBooking)
        {
            var customer = await _repo.GetCustomerById(pendingBooking.CustomerId);

            customer.FirstName = pendingBooking.CustomerFirstName;
            customer.LastName  = pendingBooking.CustomerLastName;
            customer.Title     = pendingBooking.CustomerTitle;

            if (customer.Address == null)
            {
                customer.Address = new Address();
            }

            customer.Address.AddressLine1 = pendingBooking.CustomerAddressLine1;
            customer.Address.AddressLine2 = pendingBooking.CustomerAddressLine2;
            customer.Address.AddressLine3 = pendingBooking.CustomerAddressLine3;
            customer.Address.Postcode     = pendingBooking.CustomerPostcode;
            customer.Address.Country      = pendingBooking.CustomerCountry;
            customer.Address.ModifiedBy   = pendingBooking.CreatedBy;
            customer.Address.ModifiedDate = DateTime.Now;
            customer.LandLine             = pendingBooking.CustomerLandline;
            customer.MobileNo             = pendingBooking.CustomerMobile;
            customer.ModifiedDate         = DateTime.Now;
            customer.ModifiedBy           = pendingBooking.CreatedBy;

            return(customer);
        }
Exemple #4
0
        private Holiday CreateHolidayFromPendingBooking(PendingBooking pendingBooking, Cottage cottage, Customer customer, PaymentIntent paymentIntent)
        {
            var holiday = new Holiday {
                Customer         = customer,
                Cottage          = cottage,
                NumberOfAdults   = pendingBooking.NumberOfAdults,
                NumberOfChildren = pendingBooking.NumberOfChildren,
                NumberOfInfants  = pendingBooking.NumberOfInfants,
                FirstNight       = pendingBooking.ArrivalDate,
                LastNight        = pendingBooking.LeavingDate,
                TotalCost        = pendingBooking.TotalCost,
                CreatedBy        = pendingBooking.CreatedBy
            };

            holiday.DepositPaid = paymentIntent.AmountReceived / 100;

            if (holiday.DepositPaid == holiday.TotalCost)
            {
                holiday.PaymentStatus = PaymentStatus.PaidInFull;
            }
            else
            {
                holiday.PaymentStatus = PaymentStatus.DepositPaid;
            }

            _repo.Add <Holiday>(holiday);

            return(holiday);
        }
 public void EnqueuePendingBooking(PendingBooking pendingBooking)
 {
     if (!pendingBookingsQueue.Any(x => x != null && x.MeetingKey == pendingBooking.MeetingKey))
     {
         pendingBookingsQueue.Enqueue(pendingBooking);
         logger.Info("Pending appointment added to its concurrent queue successfully");
     }
 }
Exemple #6
0
        public void DeletePendingBooking(int id)
        {
            var pendingBooking = new PendingBooking()
            {
                Id = id
            };

            _context.Remove(pendingBooking);
        }
Exemple #7
0
 public PendingBooking ToEntity(PendingBooking entity = null)
 {
     if (entity == null)
     {
         entity = new PendingBooking();
     }
     entity.Date           = Date;
     entity.ExpirationDate = ExpirationDate;
     entity.EvenScheduleId = EvenScheduleId;
     return(entity);
 }
Exemple #8
0
        private async Task <Cottage> UpdateCottageCalendar(PendingBooking pendingBooking)
        {
            var cottageAndCalendar = await _repo.GetCottageById(pendingBooking.CottageId, true, false);

            var holidayDays = cottageAndCalendar.Calendar.Where(d => d.BookingDate >= pendingBooking.ArrivalDate &&
                                                                d.BookingDate < pendingBooking.LeavingDate).ToList();

            holidayDays.ForEach(d => {
                d.BookingStatus = Enums.BookingStatus.Booked;
                d.ModifiedDate  = DateTime.Now;
                d.ModifiedBy    = pendingBooking.CreatedBy;
            });

            return(cottageAndCalendar);
        }
        public async Task ThrowExceptionWhenSameSeatSelected()
        {
            // Arrange
            using (var context = DbContextHelper.GetInMemoryDbContext())
            {
                var  service             = new BookingService(context);
                Guid id                  = Guid.NewGuid();
                var  pendingBookingFirst = new PendingBooking()
                {
                    Id                      = id,
                    Date                    = DateTime.Now,
                    EvenScheduleId          = _seedService.EvenSchedules[1].Id,
                    ExpirationDate          = DateTime.Now.AddMinutes(2),
                    PendingBookingPositions = new List <PendingBookingPosition>
                    {
                        new PendingBookingPosition
                        {
                            PendingBookingId       = id,
                            ServicePlacePositionId = _seedService.ServicePlacePositions[1].Id
                        }
                    }
                };
                var idSecond             = Guid.NewGuid();
                var pendingBookingSecond = new PendingBooking()
                {
                    Id                      = idSecond,
                    Date                    = DateTime.Now,
                    EvenScheduleId          = _seedService.EvenSchedules[1].Id,
                    ExpirationDate          = DateTime.Now.AddMinutes(2),
                    PendingBookingPositions = new List <PendingBookingPosition>
                    {
                        new PendingBookingPosition
                        {
                            PendingBookingId       = idSecond,
                            ServicePlacePositionId = _seedService.ServicePlacePositions[1].Id
                        }
                    }
                };

                // Act
                await service.CreatePendingBookingAsync(pendingBookingFirst);

                // Assert
                await Assert.ThrowsAsync <BookingException>(async() => await service.CreatePendingBookingAsync(pendingBookingSecond));
            }
        }
Exemple #10
0
        public async Task <Holiday> UpdatesForNewBooking(PendingBooking pendingBooking, PaymentIntent paymentIntent)
        {
            var updatedCottageAndCalendar = await UpdateCottageCalendar(pendingBooking);

            var updatedCustomer = await UpdateCustomer(pendingBooking);

            var holiday = CreateHolidayFromPendingBooking(pendingBooking, updatedCottageAndCalendar, updatedCustomer, paymentIntent);

            if (holiday != null)
            {
                pendingBooking.Status = PendingBookingStatus.HolidayCreated;
            }

            await _repo.Commit();

            return(holiday);
        }
Exemple #11
0
        private void AddCustAndPartyToPendingBooking(PendingBooking updatedPendingBooking,
                                                     ref PendingBooking pendingBookingFromDb)
        {
            pendingBookingFromDb.CustomerFirstName    = updatedPendingBooking.CustomerFirstName;
            pendingBookingFromDb.CustomerLastName     = updatedPendingBooking.CustomerLastName;
            pendingBookingFromDb.CustomerTitle        = updatedPendingBooking.CustomerTitle;
            pendingBookingFromDb.CustomerAddressLine1 = updatedPendingBooking.CustomerAddressLine1;
            pendingBookingFromDb.CustomerAddressLine2 = updatedPendingBooking.CustomerAddressLine2;
            pendingBookingFromDb.CustomerAddressLine3 = updatedPendingBooking.CustomerAddressLine3;
            pendingBookingFromDb.CustomerPostcode     = updatedPendingBooking.CustomerPostcode;
            pendingBookingFromDb.CustomerCountry      = updatedPendingBooking.CustomerCountry;
            pendingBookingFromDb.CustomerLandline     = updatedPendingBooking.CustomerLandline;
            pendingBookingFromDb.CustomerMobile       = updatedPendingBooking.CustomerMobile;

            pendingBookingFromDb.NumberOfAdults   = updatedPendingBooking.NumberOfAdults;
            pendingBookingFromDb.NumberOfChildren = updatedPendingBooking.NumberOfChildren;
            pendingBookingFromDb.NumberOfInfants  = updatedPendingBooking.NumberOfInfants;
        }
Exemple #12
0
        public async Task <PendingBooking> AddPaymentIntentToPendingBooking(PendingBooking pendingBooking, decimal amtForStripe)
        {
            StripeConfiguration.ApiKey = _config["Stripe:SecretKey"];

            var paymentIntentService = new PaymentIntentService();

            PaymentIntent intent;

            if (string.IsNullOrEmpty(pendingBooking.StripePaymentIntentId))
            {
                var options = new PaymentIntentCreateOptions
                {
                    Amount             = (long)amtForStripe * 100,
                    Currency           = "gbp",
                    PaymentMethodTypes = new List <string> {
                        "card"
                    }
                };

                intent = await paymentIntentService.CreateAsync(options);

                pendingBooking.StripePaymentIntentId = intent.Id;
                pendingBooking.StripeClientSecret    = intent.ClientSecret;
                pendingBooking.StripeAmount          = (int)intent.Amount / 100;
            }
            else
            {
                var options = new PaymentIntentUpdateOptions
                {
                    Amount = (long)amtForStripe * 100
                };

                intent = await paymentIntentService.UpdateAsync(pendingBooking.StripePaymentIntentId, options);

                pendingBooking.StripeAmount = (int)intent.Amount / 100;
            }

            // commit amended pendingBookings entity
            await _repo.Commit();

            return(pendingBooking);
        }
Exemple #13
0
        public async Task <PendingBooking> CreatePendingBookingAsync(PendingBooking pendingBooking)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                foreach (var position in pendingBooking.PendingBookingPositions)
                {
                    if (_context.PendingBookingPositions.Include(x => x.PendingBooking)
                        .Any(x => x.PendingBooking.EvenScheduleId == pendingBooking.EvenScheduleId &&
                             x.PendingBooking.ExpirationDate > DateTime.Now &&
                             x.ServicePlacePositionId == position.ServicePlacePositionId))
                    {
                        throw new BookingException("Already extists booking for that place.");
                    }
                }
                _context.PendingBookingPositions.AddRange(pendingBooking.PendingBookingPositions);
                _context.PendingBookings.Add(pendingBooking);
                await _context.SaveChangesAsync();

                transaction.Commit();
            }
            return(await _context.PendingBookings.Include(x => x.PendingBookingPositions).ThenInclude(x => x.ServicePlacePosition).FirstOrDefaultAsync(x => x.Id == pendingBooking.Id));
        }
        private void MyReceiveCompleted(Object source, ReceiveCompletedEventArgs asyncResult)
        {
            // Connect to the queue.
            mq = (MessageQueue)source;
            try
            {
                Message              msg = mq.EndReceive(asyncResult.AsyncResult);
                PendingBooking       pb  = null;
                UpdatedBooking       ub  = null;
                BlockBooking         bb  = null;
                ChangedAppointment   ca  = null;
                CancelledAppointment cancelledAppointment = null;
                string label = (string)msg.Label;
                logger.Info("label created fine"); //temp changes should be removed
                if (label == "pending")
                {
                    msg.Formatter = new XmlMessageFormatter(new Type[] { typeof(PendingBooking) });
                    logger.Info("pending formatter  created fine");//temp changes should be removed
                    pb = (PendingBooking)msg.Body;
                    logger.Info("#STPendingSAR# " + pb.MeetingKey + " " + DateTime.UtcNow.Ticks);
                    logger.Info("pendingbookin conversion  created fine");          //temp changes should be removed
                                                                                    // Display the message information on the screen.
                    logger.Info("pendingbooking meeting key" + pb.MeetingKey);      //temp changes should be removed
                    logger.Info("PendingBookingList Status " + PendingBookingList); //temp changes should be removed
                    logger.Info("#STPendingSAEN# " + pb.MeetingKey + " " + DateTime.UtcNow.Ticks);
                    EnqueuePendingBooking(pb);
                }
                else if (label == "update")
                {
                    msg.Formatter = new XmlMessageFormatter(new Type[] { typeof(UpdatedBooking) });
                    logger.Info("update formatter  created fine");  //temp changes should be removed
                    ub = (UpdatedBooking)msg.Body;
                    logger.Info("update conversion  created fine"); //temp changes should be removed
                                                                    // Display the message information on the screen.
                    EnqueueUpdatedMSSBooking(ub);
                }
                else if (label == "Create Appointment" || label == "Update Appointment")
                {
                    msg.Formatter = new XmlMessageFormatter(new Type[] { typeof(ChangedAppointment) });
                    logger.Info("Appointment formatter  created fine");  //temp changes should be removed
                    ca = (ChangedAppointment)msg.Body;
                    logger.Info("Appointment conversion  created fine"); //temp changes should be removed

                    EnqueueChangedAppointment(ca);
                }
                else if (label == "Delete Appointment")
                {
                    logger.Info("start reading deleted appointment");
                    msg.Formatter = new XmlMessageFormatter(new Type[] { typeof(CancelledAppointment) });
                    logger.Info("Appointment formatter  created fine");
                    cancelledAppointment = (CancelledAppointment)msg.Body;
                    logger.Info("Appointment conversion  created fine");

                    EnqueueCancelledAppointment(cancelledAppointment);
                }
                else if (label == "blockbooking")
                {
                    msg.Formatter = new XmlMessageFormatter(new Type[] { typeof(BlockBooking) });
                    logger.Info("Block booking formatter created successfully");
                    bb = (BlockBooking)msg.Body;
                    logger.Info("Block booking conversion was successful"); //temp log
                    EnqueueBlockBooking(bb);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error in ReceiveComplete Event : Block Booking - Exception = " + ex.StackTrace + " " + ex.Message);
            }
            mq.BeginReceive();
        }
Exemple #15
0
 public PendingBooking CreatePendingBooking(PendingBooking pendingBooking)
 {
     throw new NotImplementedException();
 }