private BedBooking Reserve(Client client, ShelterType shelterType, Shelter shelter)
        {
            var availablebeds = _dbContext.Beds.Where(x => x.Shelter.Type == shelterType && x.BedStatus == BedStatus.Vacant).ToList();

            //var firstAvailableBed = shelter.Beds.Find(x => x.BedStatus == BedStatus.Vacant);
            if (!availablebeds.Any())
            {
                return(null);
            }

            availablebeds[0].BedStatus = BedStatus.Occupied;
            return(new BedBooking()
            {
                ClientId = client.Id,
                Bed = availablebeds[0],
                Shelter = availablebeds[0].Shelter,
                CheckInDate = DateTime.Today
            });
        }
        public ShelterMatcherResponse Match(Client client, ShelterType shelterType, HomelessHelperDbContext dbContext)
        {
            var shelterFinder = new ShelterFinder();

            var shelter = shelterFinder.Find(shelterType);

            if (shelter != null && shelter.Any())
            {
                var bedFinder = new RoomBedFinder();

                var availableBeds = bedFinder.Find(shelter[0].Id, DateTime.Today);
                if (availableBeds != null && availableBeds.Any())
                {
                    shelter[0].Bookings.Add(new BedBooking
                    {
                        Bed         = availableBeds[0],
                        ClientId    = client.Id,
                        CheckInDate = DateTime.Today,
                    });
                    return(new ShelterMatcherResponse
                    {
                        IsBooked = true,
                        Shelter = shelter[0],
                        Message = $"Shelter Name : {shelter[0].Name}. Bed Number : {availableBeds[0].Number}",
                        Name = $"{client.FirstName} {client.LastName}",
                        Address = shelter[0].Address
                    });
                }
                return(new ShelterMatcherResponse
                {
                    Message = "No shelter available",
                    Name = $"{client.FirstName} {client.LastName}"
                });
            }
            return(new ShelterMatcherResponse
            {
                Message = "No shelter available",
                Name = $"{client.FirstName} {client.LastName}"
            });
        }
Esempio n. 3
0
        public List <Shelter> Find(ShelterType shelterType)
        {
            var dbContext = new HomelessHelperDbContext();

            return(dbContext.Shelters.Where(x => x.Type == shelterType).Include(x => x.Bookings).Include(x => x.Address).ToList());
        }