private Ticket InaccurateEquals(TurnstileScan scan)
        {
            var code          = scan.code.Substring(0, scan.code.Length - 2);
            var minCodeLength = 4;

            if (code.Length < minCodeLength)
            {
                throw new CodeToShort(VerificationMethod.Barcode, minCodeLength);
            }

            var tickets = _db.Tickets.Where(t => t.Number.StartsWith(code));

            if (tickets.Count() > 1)
            {
                throw new MultipleTicketsFound(VerificationMethod.Barcode, tickets.Count());
            }

            var ticket = tickets.FirstOrDefault();

            if (ticket == null)
            {
                throw new TicketNotFound(VerificationMethod.Barcode);
            }

            return(ticket);
        }
        public Ticket Find(TurnstileScan barcode)
        {
            Ticket ticket;

            try
            {
                ticket = StrictEquals(barcode);
            }
            catch (TicketNotFound)
            {
                ticket = InaccurateEquals(barcode);
            }

            var concert = _db.Events.FirstOrDefault(e => e.Id == ticket.EventId);

            if (concert == null)
            {
                throw new ConcertNotFound(VerificationMethod.Barcode);
            }
            ;

            // TimeSpan dateDiff = _dateTimeProvider.Now - concert.Time;
            // var hoursDiff = Math.Abs(dateDiff.TotalHours);
            // if (dateDiff.TotalHours <= -12) {
            //     throw new TooEarly(VerificationMethod.Barcode, hoursDiff);
            // }

            // if (dateDiff.TotalHours >= 12) {
            //     throw new TooLate(VerificationMethod.Barcode, hoursDiff);
            // }

            return(ticket);
        }
Exemplo n.º 3
0
        public Ticket Find(TurnstileScan barcode)
        {
            var ticket        = _db.Tickets.FirstOrDefault(t => t.Number == barcode.code);
            var anotherTicket = _db.Tickets
                                .AsEnumerable()
                                .FirstOrDefault(t => t.Number == barcode.code);

            if (ticket == null)
            {
                throw new TicketNotFound(VerificationMethod.Manual);
            }
            ;
            return(ticket);
        }
Exemplo n.º 4
0
        public Ticket Find(TurnstileScan barcode)
        {
            _log.LogInformation("Find ticket using verification method: {0}", barcode.method);
            if (barcode.method == VerificationMethod.Barcode)
            {
                return(_barcodeTicketFinder.Find(barcode));
            }

            if (barcode.method == VerificationMethod.Manual)
            {
                return(_manualTicketFinder.Find(barcode));
            }

            throw new Exception($"Verification method doesn't exist: {barcode.method}");
        }
        private Ticket StrictEquals(TurnstileScan scan)
        {
            var tickets = _db.Tickets.Where(t => t.Number == scan.code);

            if (tickets.Count() > 1)
            {
                throw new MultipleTicketsFound(VerificationMethod.Barcode, tickets.Count());
            }

            var ticket = tickets.FirstOrDefault();

            if (ticket == null)
            {
                throw new TicketNotFound(VerificationMethod.Barcode);
            }

            return(ticket);
        }