Ejemplo n.º 1
0
 public async Task <PassInformationViewModel> GetActivePass(int lang, int id)
 {
     _logger.LogInfo("Trying to get active passes with id " + id + " on language " + lang);
     try
     {
         PassInformationViewModel passInformation = _mapper.Map <PassInformation, PassInformationViewModel>(await _passRepository.GetActivePass(id));
         if (passInformation == null)
         {
             _logger.LogInfo("Pass information not available with id " + id + " on language " + lang);
             throw new Exception(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPassInformation)));
         }//Filter based on language from the paginated result.
         passInformation?.PassDescription?.FirstOrDefault(p => p.SelectedLanguage == lang);
         _logger.LogInfo("Retrieved active pass with id " + id + " on language " + lang);
         return(passInformation);
     }
     catch (Exception ex)
     {
         _logger.LogInfo(ex.Message);
         return(null);
     }
 }
Ejemplo n.º 2
0
        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));
            }
        }