public TravellerResponse SubmitFeedback(TravellerFeedbackViewModel feedbackData)
        {
            _logger.LogInfo("Trying to submit feedback with device id " + feedbackData.DeviceId);
            try
            {
                //Get Traveller info based on device id
                Traveller traveller = _travellerRepository.GetTravellerByDeviceId(feedbackData.DeviceId);
                if (traveller == null)
                {
                    throw new Exception(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.BookingWithInvalidDeviceId)));
                }

                //Convert view model to entity
                TravellerFeedback feedbackInfo = _mapper.Map <TravellerFeedback>(feedbackData);
                feedbackInfo.TravellerId = traveller.Id;
                feedbackInfo.IsActive    = true;
                _travellerRepository.SubmitFeedback(feedbackInfo);
                _logger.LogInfo("Successfully submitted feedback with device id " + feedbackData.DeviceId);
                feedbackData.DeviceId = null;
                TravellerResponse response = new TravellerResponse(true, string.Format(_messageHandler.GetSuccessMessage(SuccessMessagesEnum.SuccessfullySaved)));
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new TravellerResponse(false, ex.Message));
            }
        }
        public async Task <TravellerResponse> ActivatePass(string uId)
        {
            _logger.LogInfo("Trying to activate pass with booking id " + uId);
            try
            {
                _logger.LogInfo("Retrieved booking information with booking id " + uId);
                BookedPassInformation bookingInformation = await _travellerRepository.GetBookingDatails(uId);

                if (bookingInformation.PassInformation == null)
                {
                    _logger.LogInfo(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.NullException), " No pass information available"));
                    throw new Exception(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPassInformation)));
                }
                if (bookingInformation.QRCode == null)
                {
                    _logger.LogInfo(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.NullException), " Invalid QR code information"));
                    throw new Exception(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidQRCode)));
                }
                // Check If already pass has expired and trying to activate again then throw exception
                if (bookingInformation.QRCode.IsActive)
                {
                    throw new Exception(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPassInformation)));
                }

                bookingInformation.QRCode.PassActivatedDate        = DateTime.Now;
                bookingInformation.QRCode.IsActive                 = true;
                bookingInformation.QRCode.ActivatedPassExpiredDate = DateTime.Now;

                if (bookingInformation.PassInformation.PassValidityInDays > 0)
                {
                    bookingInformation.QRCode.ActivatedPassExpiredDate = bookingInformation.QRCode.ActivatedPassExpiredDate.AddDays(bookingInformation.PassInformation.PassValidityInDays);
                }

                if (bookingInformation.PassInformation.PassValidityInHours > 0)
                {
                    bookingInformation.QRCode.ActivatedPassExpiredDate = bookingInformation.QRCode.ActivatedPassExpiredDate.AddHours(bookingInformation.PassInformation.PassValidityInHours);
                }

                bookingInformation.QRCode.PassExpiredDuraionDate = bookingInformation.PassInformation.PassExpiredDate;
                bookingInformation.QRCode.QRCodeImage            = null;

                _travellerRepository.ActivatePass(bookingInformation.QRCode);
                _logger.LogInfo("Successfully activated pass with booking id " + uId);
                TravellerResponse response = new TravellerResponse(true, string.Format(_messageHandler.GetSuccessMessage(SuccessMessagesEnum.SuccessfullyActivated)));
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new TravellerResponse(false, ex.Message));
            }
        }
        public async Task <TravellerResponse> BookPass(BookedPassInformationViewModel bookingInfo)
        {
            _logger.LogInfo("Trying to book pass having id " + bookingInfo.PassInformationId + "with traveller id " + bookingInfo.TravellerDeviceId);
            try
            {
                //Get selected pass information based on id
                PassInformationViewModel passInformation = _mapper.Map <PassInformation, PassInformationViewModel>(await _passRepository.GetActivePass(bookingInfo.PassInformationId));
                if (passInformation == null)
                {
                    throw new Exception(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPassInformation)));
                }

                //Get active user based on device id
                Traveller travellerInfo    = new Traveller();
                var       isExistTraveller = _travellerRepository.GetTravellerByDeviceId(bookingInfo.TravellerDeviceId);
                if (isExistTraveller == null)
                {
                    //Add traveller information
                    travellerInfo.DeviceId   = bookingInfo.TravellerDeviceId;
                    travellerInfo.DeviceType = bookingInfo.TravellerDeviceType;
                    travellerInfo.IsActive   = true;

                    //Added new traveller
                    _travellerRepository.AddTraveller(travellerInfo);
                    _logger.LogInfo("Successfully added new traveller with device id " + bookingInfo.TravellerDeviceId);

                    //Once traveller info added then get the traveller id
                    isExistTraveller = _travellerRepository.GetTravellerByDeviceId(bookingInfo.TravellerDeviceId);
                }

                //Business logic goes here for booking pass information
                bookingInfo.TravellerId            = isExistTraveller.Id;
                bookingInfo.UniqueReferrenceNumber = "HST-" + bookingInfo.TravellerId + "-" + DateTime.Now.ToString("ddMMyyhhmmssff");
                bookingInfo.TransactionNumber      = DateTime.Now.ToString("ddMMyyhhmmssff");
                bookingInfo.BookingDate            = DateTime.Today;
                bookingInfo.TotalAmout             = (bookingInfo.Adult * passInformation.AdultPrice) + (bookingInfo.Child * passInformation.ChildPrice);
                bookingInfo.IsActive = true;
                bookingInfo.QRCode   = null;
                // QR code information to be stored with booking information id
                QRCodeViewModel qrCode = new QRCodeViewModel();
                //bookingInfo.PaymentStatus = true;
                //bookingInfo.IsActive = true;
                //bookingInfo.PaymentResponse = "Success";
                qrCode.IsActive = false;
                qrCode.BookedPassInformationId = bookingInfo.Id;
                qrCode.PassExpiredDuraionDate  = passInformation.PassExpiredDate;
                bookingInfo.QRCode             = qrCode;
                ///////////////////////////////////////////////////////////////
                if (bookingInfo.TotalAmout == 0)
                {
                    throw new Exception(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPassengerInformation)));
                }
                _travellerRepository.BookPass(_mapper.Map <BookedPassInformation>(bookingInfo));
                _logger.LogInfo("Successfully addded booking information");
                TravellerResponse response = new TravellerResponse(true, string.Format(_messageHandler.GetSuccessMessage(SuccessMessagesEnum.SuccessfullySaved)));
                response.Result = bookingInfo.UniqueReferrenceNumber;
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new TravellerResponse(false, ex.Message));
            }
        }