Esempio n. 1
0
        public bool SendNotification(BookingResponse bookingResponse)
        {
            SmtpClient smtp = new SmtpClient();
            MailMessage message = new MailMessage();
            message.Sender = new MailAddress(SenderEmailAddress);
            message.From = new MailAddress(bookingResponse.Guest.EMailAddress);
            message.Subject = NotificationMailTitlePrefix + bookingResponse.BookingStatus.ToString();
            if (bookingResponse.BookingStatus ==BookingStatus.Rejected)
            {
                message.Body = string.Format(@"Dear Customer, We regret to inform you that your booking against
                                                reservation number {0} was not successful.", bookingResponse.ReservationId);
            }
            else
            {
                message.Body = string.Format(@"Dear Customer, We are happy to inform you
                                that your booking against reservation number {0} is Confirmed and your confirmation number is {1}.",
                                bookingResponse.ReservationId, bookingResponse.ConfirmationNumber);
            }

            try
            {
                smtp.Send(message);
            }
            catch
            {
                // todo : logging
                return false;
            }

            return true;
        }
Esempio n. 2
0
        public bool SetBookingRequestComplete(BookingResponse bookingResponse, IQueueConfig queueConfig)
        {
            try
            {
                try
                {
                    string fileName = bookingResponse.ReservationId + ".txt";

                    if (File.Exists(Path.Combine(queueConfig.PendingBookingQueuePath, fileName)))
                    {
                        string queuePathToMove = string.Empty;
                        switch (bookingResponse.BookingStatus)
                        {
                            case BookingStatus.Confirmed:
                                queuePathToMove = queueConfig.ConfirmedBookingQueuePath;
                                break;
                            case BookingStatus.Rejected:
                                queuePathToMove = queueConfig.RejectedNotificationQueuePath;
                                break;
                            case BookingStatus.Booked:
                                queuePathToMove = queueConfig.PendingBookingQueuePath;
                                break;
                            default:
                                queuePathToMove = queueConfig.ErrorQueuePath;
                                break;
                        }

                        // move file to error queue
                        File.Move(Path.Combine(queueConfig.PendingBookingQueuePath, fileName), Path.Combine(queuePathToMove, fileName));

                        return true;
                    }

                }
                catch
                {

                }

            }
            catch
            {
                // todo logging

            }

            return false;
        }
Esempio n. 3
0
        public BookingResponse ReadQueue(BookingRequest request)
        {
            var response = new BookingResponse();
            using (var context = new SpartanHotelsEntities())
            {
                var queue = context.Queues.FirstOrDefault(q => (q.ReservationID == request.BookingId));

                if (queue != null)
                {
                    response.ReservationId = queue.ReservationID;
                    response.ReservationId = queue.ReservationID;
                    response.ReservationId = queue.ReservationID;
                }
                else
                {
                    //return.. invalid input, queue doesnt exists
                }
            }

            return response;
        }
Esempio n. 4
0
        public BookingResponse AddBooking(BookingRequest request)
        {
            var response = new BookingResponse();

            try
            {
                using (var context = new SpartanHotelsEntities())
                {
                    var eHotel = (from hr in context.HotelRooms
                                  join ht in context.Hotels on hr.HotelID equals ht.HotelID
                                  where hr.HotelRoomID.ToString() == request.TravelDetails.HotelID
                                  select new
                                      {
                                          hr.HotelID,
                                          hr.HotelRoomID,
                                          ht.HotelName,
                                          ht.Locality,
                                          ht.City
                                      }).FirstOrDefault();

                    if (eHotel != null)
                    {
                        var availabilityResponse = GetAvailableRoomList(
                            new AvailabilityRequest
                                {
                                    City = eHotel.City,
                                    FromDate = request.TravelDetails.FromDate,
                                    ToDate = request.TravelDetails.ToDate,
                                    RequestedRoomCount = request.RequestedRooms.Count()
                                });

                        var available = false;
                        foreach (var rr in request.RequestedRooms)
                        {
                            if (
                                availabilityResponse.Rooms.FirstOrDefault(
                                    ar => ar.Room.Title == rr.RequestedRoom.Title && ar.AvailableCount >= rr.RoomCount) !=
                                null)
                            {
                                available = true;
                            }
                            else
                            {
                                available = false;
                                break;
                            }
                        }

                        if (available)
                        {
                            var eCustomer = AddCustomer(request.Guest.FirstName, request.Guest.LastName,
                                                        request.Guest.EMailAddress);

                            var eReservation = new Reservation
                                {
                                    BookingNum = request.BookingId,
                                    HotelRoomID = Convert.ToInt32(request.TravelDetails.HotelID),
                                    FromDate = request.TravelDetails.FromDate,
                                    ToDate = request.TravelDetails.ToDate,
                                    ConfirmationNum = context.Reservations.Max(c => c.ConfirmationNum) + 1,
                                    CreatedBy = "",
                                    CreatedDate = DateTime.Now,
                                    ModifiedBy = "",
                                    ModifiedDate = DateTime.Now,
                                    CustomerID = eCustomer.CustomerID,
                                    BookStatusID = (int) BookingStatus.Confirmed,
                                    Remarks = ""
                                };

                            foreach (var rm in request.RequestedRooms)
                            {
                                eReservation.HotelRoomID = Convert.ToInt32(rm.RequestedRoom.Id);

                                context.Reservations.Add(eReservation);
                            }

                            context.SaveChanges();

                            response.ConfirmationNumber = eReservation.ConfirmationNum.ToString();
                            response.BookingStatus = (BookingStatus) eReservation.BookStatusID;
                            response.Guest = new Entities.Customer
                                {
                                    EMailAddress = eCustomer.Email,
                                    FirstName = eCustomer.FirstName,
                                    LastName = eCustomer.LastName
                                };
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return response;
        }