public async Task <IEnumerable <UserSnapshotDto> > HandleAsync(GetUserSnapshotsForBusiness query) { var users = await _userRepository.GetUsersByBusinessId(query.BusinessId); var ret = new List <UserSnapshotDto>(); foreach (var user in users) { //TODO: This could get these all in one go then iterate the list in memory. (FirstOrDefault()) var state = await _statusRepository.GetStatusForUserAsync(user.Id); //TODO: Could get list of sites and access then from memory. var siteName = await _siteRepository.GetSiteNameAsync(state.SiteId); ret.Add(new UserSnapshotDto { Id = user.Id, Initials = $"{user.FirstName[0]}{user.SecondName[0]}", LastAction = state.CurrentState.ToString(), LastTime = state.Updated.ToShortTimeString(), Name = user.FirstName + " " + user.SecondName, SiteName = siteName, AccountId = user.AccountId }); } return(ret.OrderBy(r => r.Name)); }
public async Task Update(Guid userId, AccessAction action, Guid siteId) { var status = await repository.GetStatusForUserAsync(userId); if (status is null) { logger.LogInformation("No status found creating one now for user: "******"Updated users status {userId} to: {action}"); status.Update(action, siteId); await repository.UpdateAsync(status); }