Exemplo n.º 1
0
        public BarcodeQueryResult Handle(BarcodeQuery query)
        {
            try
            {
                var eventTicketDetails = _eventTicketDetailRepository.GetRASVRideEventTicketDetails()
                                         .ToDictionary(k => k.Id, k => k);

                var matchSeatTicketDetail = _matchSeatTicketDetailRepository.GetByBarcodeNumberAndEventTicketDetailIds(query.BarcodeNumber, eventTicketDetails.Keys);
                if (matchSeatTicketDetail != null)
                {
                    var transaction        = _transactionRepository.Get((long)matchSeatTicketDetail.TransactionId);
                    var eventTicketDetail  = eventTicketDetails[matchSeatTicketDetail.EventTicketDetailId];
                    var additionalInfo     = _eventTicketAttributeRepository.GetByEventTicketDetailId(eventTicketDetail.Id).AdditionalInfo;
                    var value              = JsonConvert.DeserializeObject <TicketValue>(additionalInfo).value;
                    var ticketCategoryId   = eventTicketDetail.TicketCategoryId;
                    var ticketCategoryName = _ticketCategoryRepository.Get((int)ticketCategoryId).Name.ToString();
                    var currencyId         = transaction.CurrencyId;
                    var transactionUTC     = transaction.CreatedUtc;
                    var currencyCode       = _currencyTypeRepository.GetById(currencyId).Code.ToString();
                    var userAltId          = transaction.CreatedBy;
                    var userId             = _userRepository.GetByAltId(userAltId).Id;
                    var userAddressDetail  = _userAddressDetailRepository.GetByUser(userId);
                    var zipcodeId          = userAddressDetail != null ? userAddressDetail.Zipcode : 9;
                    var postalcode         = _zipcodeRepository.Get(zipcodeId).Postalcode;

                    var barcodeDetailsContainer = new BarcodeDetailsContainer()
                    {
                        AltId            = (System.Guid)matchSeatTicketDetail.AltId,
                        BarcodeNumber    = matchSeatTicketDetail.BarcodeNumber,
                        CurrencyCode     = currencyCode,
                        TicketCategoryId = ticketCategoryId,
                        TicketCategory   = ticketCategoryName,
                        Value            = value,
                        Postalcode       = postalcode,
                        IsConsumed       = matchSeatTicketDetail.IsConsumed,
                        ConsumedDateTime = matchSeatTicketDetail.ConsumedDateTime,
                        TransactionUTC   = transactionUTC,
                    };
                    return(new BarcodeQueryResult
                    {
                        BarcodeDetailsContainer = barcodeDetailsContainer,
                        IsValid = true
                    });
                }

                var offlineBarcodeDetail = _offlineBarcodeDetailRepository.GetByBarcodeNumberAndEventTicketDetailIds(query.BarcodeNumber, eventTicketDetails.Keys);
                if (offlineBarcodeDetail != null)
                {
                    var ticketCategoryId = _eventTicketDetailRepository.Get(offlineBarcodeDetail.EventTicketDetailId)
                                           .TicketCategoryId;
                    var ticketCategoryName = _ticketCategoryRepository.Get((int)ticketCategoryId).Name;
                    var currencyCode       = _currencyTypeRepository.GetById(offlineBarcodeDetail.CurrencyId).Code;

                    var barcodeDetailsContainer = new BarcodeDetailsContainer
                    {
                        AltId            = offlineBarcodeDetail.AltId,
                        BarcodeNumber    = offlineBarcodeDetail.BarcodeNumber,
                        CurrencyCode     = currencyCode,
                        TicketCategoryId = ticketCategoryId,
                        TicketCategory   = ticketCategoryName,
                        Value            = offlineBarcodeDetail.Price,
                        Postalcode       = "",
                        IsConsumed       = offlineBarcodeDetail.IsConsumed,
                        ConsumedDateTime = offlineBarcodeDetail.ConsumedDateTime,
                    };
                    return(new BarcodeQueryResult
                    {
                        BarcodeDetailsContainer = barcodeDetailsContainer,
                        IsValid = true
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.Log(Logging.Enums.LogCategory.Error, ex);
            }

            return(new BarcodeQueryResult
            {
                BarcodeDetailsContainer = null,
                IsValid = false
            });
        }
        protected override async Task <ICommandResult> Handle(BarcodeRedemptionCommand command)
        {
            BarcodeRedemptionCommandResult barcodeRedemptionCommandResult = new BarcodeRedemptionCommandResult();

            try
            {
                var eventTicketDetails = _eventTicketDetailRepository.GetRASVRideEventTicketDetails()
                                         .ToDictionary(k => k.Id);
                var matchSeatTicketDetail = _matchSeatTicketDetailRepository.GetByBarcodeNumberAndEventTicketDetailIds(command.BarcodeNumber, eventTicketDetails.Keys);

                if (matchSeatTicketDetail != null)
                {
                    if (!matchSeatTicketDetail.IsConsumed)
                    {
                        matchSeatTicketDetail.IsConsumed       = true;
                        matchSeatTicketDetail.ConsumedDateTime = DateTime.UtcNow;
                        FIL.Contracts.DataModels.MatchSeatTicketDetail RedemptionResult = _matchSeatTicketDetailRepository.Save(matchSeatTicketDetail);
                        barcodeRedemptionCommandResult.Id               = RedemptionResult.Id;
                        barcodeRedemptionCommandResult.AltId            = (System.Guid)RedemptionResult.AltId;
                        barcodeRedemptionCommandResult.BarcodeNumber    = RedemptionResult.BarcodeNumber;
                        barcodeRedemptionCommandResult.IsConsumed       = RedemptionResult.IsConsumed;
                        barcodeRedemptionCommandResult.ConsumedDateTime = RedemptionResult.ConsumedDateTime;
                        barcodeRedemptionCommandResult.Success          = true;
                    }
                    else
                    {
                        barcodeRedemptionCommandResult.Id               = matchSeatTicketDetail.Id;
                        barcodeRedemptionCommandResult.AltId            = (System.Guid)matchSeatTicketDetail.AltId;
                        barcodeRedemptionCommandResult.BarcodeNumber    = matchSeatTicketDetail.BarcodeNumber;
                        barcodeRedemptionCommandResult.IsConsumed       = matchSeatTicketDetail.IsConsumed;
                        barcodeRedemptionCommandResult.ConsumedDateTime = matchSeatTicketDetail.ConsumedDateTime;
                        barcodeRedemptionCommandResult.Success          = false;
                    }
                }
                else
                {
                    var offlineBarcodeDetail = _offlineBarcodeDetailRepository.GetByBarcodeNumberAndEventTicketDetailIds(command.BarcodeNumber, eventTicketDetails.Keys);
                    if (offlineBarcodeDetail != null)
                    {
                        if (!offlineBarcodeDetail.IsConsumed)
                        {
                            offlineBarcodeDetail.IsConsumed       = true;
                            offlineBarcodeDetail.ConsumedDateTime = DateTime.UtcNow;
                            _offlineBarcodeDetailRepository.Save(offlineBarcodeDetail);
                            FIL.Contracts.DataModels.OfflineBarcodeDetail RedemptionResult = _offlineBarcodeDetailRepository.Save(offlineBarcodeDetail);
                            barcodeRedemptionCommandResult.Id               = RedemptionResult.Id;
                            barcodeRedemptionCommandResult.AltId            = RedemptionResult.AltId;
                            barcodeRedemptionCommandResult.BarcodeNumber    = RedemptionResult.BarcodeNumber;
                            barcodeRedemptionCommandResult.IsConsumed       = RedemptionResult.IsConsumed;
                            barcodeRedemptionCommandResult.ConsumedDateTime = RedemptionResult.ConsumedDateTime;
                            barcodeRedemptionCommandResult.Success          = true;
                        }
                        else
                        {
                            barcodeRedemptionCommandResult.Id               = offlineBarcodeDetail.Id;
                            barcodeRedemptionCommandResult.AltId            = offlineBarcodeDetail.AltId;
                            barcodeRedemptionCommandResult.BarcodeNumber    = offlineBarcodeDetail.BarcodeNumber;
                            barcodeRedemptionCommandResult.IsConsumed       = offlineBarcodeDetail.IsConsumed;
                            barcodeRedemptionCommandResult.ConsumedDateTime = offlineBarcodeDetail.ConsumedDateTime;
                            barcodeRedemptionCommandResult.Success          = false;
                        }
                    }
                    else
                    {
                        barcodeRedemptionCommandResult.Id      = -1;
                        barcodeRedemptionCommandResult.Success = false;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Log(Logging.Enums.LogCategory.Error, ex);
                barcodeRedemptionCommandResult.Id      = -1;
                barcodeRedemptionCommandResult.Success = false;
            }
            return(barcodeRedemptionCommandResult);
        }