コード例 #1
0
ファイル: ScansController.cs プロジェクト: qccoders/QCVOC
        public IActionResult Delete(Guid eventId, Guid serviceId, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(BadRequest($"The card or veteran ID is null or empty."));
            }

            var veteran = default(Veteran);

            if (int.TryParse(id, out var cardNumber))
            {
                veteran = VeteranRepository
                          .GetAll(new VeteranFilters()
                {
                    CardNumber = cardNumber
                })
                          .SingleOrDefault();
            }
            else if (Guid.TryParse(id, out var veteranId))
            {
                veteran = VeteranRepository.Get(veteranId);
            }
            else
            {
                return(BadRequest($"The provided ID is neither a Card Number nor Veteran ID."));
            }

            if (veteran == default(Veteran))
            {
                return(StatusCode(404, $"The specified Card Number or Veteran Id doesn't match an enrolled Veteran."));
            }

            var scan = ScanRepository.Get(eventId, veteran.Id, serviceId);

            if (scan == default(Scan))
            {
                return(StatusCode(404, $"A Scan matching the specified information could not be found."));
            }

            try
            {
                ScanRepository.Delete(eventId, veteran.Id, serviceId);
                return(NoContent());
            }
            catch (Exception ex)
            {
                throw new Exception($"Error deleting the Scan matching the specified information: {ex.Message}.  See inner Exception for details.", ex);
            }
        }
コード例 #2
0
ファイル: ScansController.cs プロジェクト: qccoders/QCVOC
        public IActionResult GetCheckIn(Guid eventId, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(BadRequest($"The card or veteran ID is null or empty."));
            }

            var veteran = default(Veteran);

            if (int.TryParse(id, out var cardNumber))
            {
                veteran = VeteranRepository
                          .GetAll(new VeteranFilters()
                {
                    CardNumber = cardNumber
                })
                          .SingleOrDefault();
            }
            else if (Guid.TryParse(id, out var veteranId))
            {
                veteran = VeteranRepository.Get(veteranId);
            }
            else
            {
                return(BadRequest($"The provided ID is neither a Card Number nor Veteran ID."));
            }

            if (veteran == default(Veteran))
            {
                return(StatusCode(404, $"The specified Card Number or Veteran Id doesn't match an enrolled Veteran."));
            }

            var scan = ScanRepository.Get(eventId, veteran.Id, Guid.Empty);

            if (scan == default(Scan))
            {
                return(StatusCode(404, $"The Veteran has not checked in for this Event."));
            }

            return(Ok(scan));
        }
コード例 #3
0
ファイル: ScansController.cs プロジェクト: qccoders/QCVOC
        public IActionResult Scan([FromBody] ScanRequest scan)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetReadableString()));
            }

            if (!int.TryParse(scan.CardNumber, out var cardNumber))
            {
                return(BadRequest($"Card Number {scan.CardNumber} is not a valid integer."));
            }

            var @event = EventRepository.Get((Guid)scan.EventId);

            if (@event == default(Event))
            {
                StatusCode(404, "The specified Event could not be found.");
            }

            var service = ServiceRepository.Get(scan.ServiceId);

            if (service == default(Service))
            {
                return(StatusCode(404, "The specified Service could not be found."));
            }

            var veteran = VeteranRepository
                          .GetAll(new VeteranFilters()
            {
                CardNumber = cardNumber, IncludePhotoBase64 = true
            })
                          .SingleOrDefault();

            if (veteran == default(Veteran))
            {
                return(StatusCode(404, $"Card Number {scan.CardNumber} doesn't match an enrolled Veteran."));
            }

            var previousScans = ScanRepository.GetAll(new ScanFilters()
            {
                EventId = scan.EventId, VeteranId = veteran.Id
            });
            var existingCheckIn = previousScans.Where(s => s.ServiceId == Guid.Empty).SingleOrDefault();

            var scanRecord = new Scan()
            {
                EventId   = (Guid)scan.EventId,
                VeteranId = veteran.Id,
                ServiceId = scan.ServiceId,
                ScanById  = User.GetId(),
                ScanDate  = DateTime.UtcNow,
                PlusOne   = scan.PlusOne,
            };

            // check in scan
            if (scan.ServiceId == Guid.Empty)
            {
                if (existingCheckIn == default(Scan))
                {
                    return(CreateScan(scanRecord, veteran));
                }
                else if (existingCheckIn.PlusOne != scanRecord.PlusOne)
                {
                    return(UpdateScan(scanRecord, veteran));
                }
                else
                {
                    return(Conflict(new ScanError(existingCheckIn, veteran, "Duplicate Scan")));
                }
            }

            // service scan
            if (existingCheckIn == default(Scan))
            {
                return(StatusCode(403, new ScanError(scanRecord, veteran, "The Veteran has not checked in for this Event.")));
            }

            if (scanRecord.PlusOne && !existingCheckIn.PlusOne)
            {
                return(StatusCode(403, new ScanError(scanRecord, veteran, "The Veteran did not check in with a +1.")));
            }

            var previousServiceScan = previousScans.Where(s => s.ServiceId == scan.ServiceId).SingleOrDefault();

            if (previousServiceScan != default(Scan))
            {
                return(Conflict(new ScanError(previousServiceScan, veteran, "Duplicate Scan")));
            }

            return(CreateScan(scanRecord, veteran));
        }
コード例 #4
0
 private Property Gettable(Veteran veteran, VeteranRepository veterans)
 => (veterans.GetAll().Count() > 0).ToProperty();