public async Task <IEnumerable <HostModel> > ReadAll() { var models = _repository.ReadAll().ToModels().ToList(); foreach (var model in models) { model.Status = _cacheService.Get(model.IpAddress); } return(await Task.FromResult(models).ConfigureAwait(false)); }
public Result <List <Reservation> > ViewByHost(Host host) { //match the host with an ID Dictionary <string, Host> hostMap = hostRepo.ReadAll() .ToDictionary(i => i.ID); foreach (var hostID in hostMap) { if (hostID.Value.Email == host.Email) { host.ID = hostID.Key; break; } } //get list of reservations List <Reservation> reservations = reservationRepo.ReadByHost(host); Dictionary <int, Guest> guestMap = guestRepo.ReadAll() .ToDictionary(i => i.ID); //return false and null list if no reservations found Result <List <Reservation> > result = new Result <List <Reservation> >(); if (reservations.Count == 0) { result.AddMessage("no reservations found for host"); } foreach (var reservation in reservations) { reservation.Host = hostMap[host.ID]; reservation.Guest = guestMap[reservation.Guest.ID]; if (reservation.Total == 0) { reservation.SetTotal(); } } result.Value = reservations.OrderBy(r => r.StartDate).ToList(); return(result); }