Example #1
0
        private Property Deleteable(Veteran veteran, VeteranRepository veterans)
        {
            veterans.Delete(veteran);
            var equal = veterans.Get(veteran.Id) == null;

            return(equal.ToProperty());
        }
Example #2
0
        private Property Insertable(Veteran veteran, VeteranRepository veterans)
        {
            var inserted = veterans.Create(veteran);
            var equal    = inserted.Equals(veteran);

            return(equal.ToProperty());
        }
Example #3
0
 private Property Lifecycle(Veteran veteran, VeteranRepository repository)
 {
     return(Insertable(veteran, repository)
            .And(Updateable(veteran, repository))
            .And(Gettable(veteran, repository))
            .And(Deleteable(veteran, repository)));
 }
Example #4
0
 public ClientInformationsController()
 {
     _regionRepository          = new RegionRepository();
     _clientInformation         = new ClientInformation();
     _countryRepository         = new CountryRepository();
     _businessTypeRepository    = new BusinessTypeRepository();
     _businessStatusRepository  = new BusinessStatusRepository();
     _counsellingTypeRepository = new CounsellingTypeRepository();
     _exportRepository          = new ExportRepository();
     _genderRepository          = new GenderRepository();
     _raceTypeRepository        = new RaceRepository();
     _sbaClientTypeRepository   = new SBAClientTypeRepository();
     _veteranTypeRepository     = new VeteranRepository();
 }
Example #5
0
        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);
            }
        }
Example #6
0
        private Property Updateable(Veteran veteran, VeteranRepository veterans)
        {
            veteran.FirstName      = "TestFirstName";
            veteran.LastName       = "TestLastName";
            veteran.CardNumber     = 1234567;
            veteran.Address        = "1111 1st street";
            veteran.PrimaryPhone   = "(123) 123-1234";
            veteran.Email          = "*****@*****.**";
            veteran.EnrollmentDate = DateTime.Now;

            var updated = veterans.Update(veteran);
            var equal   = updated.Equals(veteran);

            return(equal.ToProperty());
        }
Example #7
0
        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));
        }
Example #8
0
        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));
        }
Example #9
0
 private Property Gettable(Veteran veteran, VeteranRepository veterans)
 => (veterans.GetAll().Count() > 0).ToProperty();