Esempio n. 1
0
        public ActionResult <AdminResponse> CreateNewPass([FromBody] PassInformationViewModel passInformation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.ModelValidation), "", ModelState.Values.First().Errors.First().ErrorMessage)));
            }
            var response = _passService.CreatePass(passInformation);

            return(Ok(response));
        }
Esempio n. 2
0
        public async Task <ActionResult <AdminResponse> > UpdatePassInformation([FromBody] PassInformationViewModel passInformation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.ModelValidation), "", ModelState.Values.First().Errors.First().ErrorMessage)));
            }
            if (passInformation.Id <= 0)
            {
                return(BadRequest(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.NotValidInformations))));
            }
            var response = await _passService.UpdatePass(passInformation);

            return(Ok(response));
        }
Esempio n. 3
0
 public AdminResponse CreatePass(PassInformationViewModel passInformation)
 {
     _logger.LogInfo("Trying to add a new pass");
     try
     {
         //Pass remain active whole day(ex: 10/29/2019 23:59:59)
         passInformation.PassExpiredDate = passInformation.PassExpiredDate.AddDays(1).AddSeconds(-1);
         PassInformation passInfo = _mapper.Map <PassInformationViewModel, PassInformation>(passInformation);
         _passRepository.CreatePass(passInfo);
         _logger.LogInfo("Successfully created a new pass");
         AdminResponse response = new AdminResponse(true, string.Format(_messageHandler.GetSuccessMessage(SuccessMessagesEnum.SuccessfullySaved)));
         response.PassInformation = passInformation;
         return(response);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(new AdminResponse(false, ex.Message));
     }
 }
Esempio n. 4
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);
     }
 }
Esempio n. 5
0
        public async Task <AdminResponse> UpdatePass(PassInformationViewModel passInformation)
        {
            _logger.LogInfo("Trying to update existing pass information");
            try
            {
                _logger.LogInfo("Trying to update existing pass information");
                //Get Existing Pass info based on Pass
                PassInformation passInfo = await this._passRepository.GetActivePass(passInformation.Id);

                //If null then throw exception with invalid information
                if (passInfo == null)
                {
                    return(new AdminResponse(false, string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPassDescription))));
                }

                PassDescription passDesc = new PassDescription();
                //if null then update only Pass information otherwise update Pass description
                if (passInformation.PassDescription != null && passInformation.PassDescription.Count() > 0)
                {
                    //Get Existing Pass desc based on Pass desc id
                    passDesc = passInfo.PassDescription?.Where(p => p.Id == passInformation.PassDescription.FirstOrDefault().Id&& p.SelectedLanguage == passInformation.PassDescription.FirstOrDefault().SelectedLanguage&& p.IsActive).FirstOrDefault();

                    //Pass remain active whole day(ex: 10/29/2019 23:59:59)
                    passInformation.PassExpiredDate = passInformation.PassExpiredDate.AddDays(1).AddSeconds(-1);

                    ////mapped view model to entity
                    passInfo = _mapper.Map <PassInformation>(passInformation);

                    //If null then add new Pass desc with selected language otherwise update existing Pass desc.
                    if (passDesc != null)
                    {
                        //update existing entity from edited by user
                        passDesc = passInfo.PassDescription.FirstOrDefault();

                        //Updated Pass information
                        _passRepository.UpdatePass(passInfo);
                        _logger.LogInfo("Successfully updated Pass information");

                        //Updated pass description
                        _passDescriptionRepository.UpdatePassDesc(passDesc);
                        _logger.LogInfo("Successfully updated Pass Description information");

                        //If selected Pass has already been added then remove all assigned pass along with PTO information from mapper table
                        _passActivePTOMapper.BulkDeletePass(passInfo.Id);
                        _logger.LogInfo("Removed all assigned PTOs with Pass information from mapper table");

                        //Add new updated PTOs for a pass information in Mapper table
                        _passActivePTOMapper.BulkAddPTO(passInfo.PassActivePTOs.ToArray());
                        _logger.LogInfo("Successfully added PTOs information in mapper table");
                    }
                    else
                    {
                        //Added new Pass description if new language selected by user
                        _passDescriptionRepository.AddPassDesc(passInfo.PassDescription.FirstOrDefault());
                        _logger.LogInfo("Successfully added Pass description information");
                    }
                }
                else
                {
                    return(new AdminResponse(false, string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPassDescription))));
                }

                AdminResponse response = new AdminResponse(true, "Successfully saved");
                response.PassInformation = passInformation;
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new AdminResponse(false, ex.Message));
            }
        }
Esempio n. 6
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));
            }
        }