public async Task <IEnumerable <UserDto> > GetAllAsync() { var users = await _userProvider?.GetAsync(); var localUsers = await _unitOfWork.Users.GetAllAsync(); return(users.Where(x => localUsers.SingleOrDefault(l => l.GlobalId == x.id) != null)); }
public async Task <IEnumerable <UserDto> > SyncWithRemoteUsers() { try { var users = await _userProvider.GetAsync(); foreach (var user in users) { var localUser = await _unitOfWork.Users.Query.SingleOrDefaultAsync(u => u.GlobalId == user.id); if (localUser == null) { var deletedUser = await _unitOfWork.Users.Deleted.SingleOrDefaultAsync(u => u.GlobalId == user.id); if (deletedUser == null) { localUser = new User() { GlobalId = user.id, IsDeleted = false }; _unitOfWork.Users.Create(localUser); var usersWithPermissions = new List <User>(); usersWithPermissions.Add(localUser); _unitOfWork.Spaces.Create(new Space() { Name = "My Space", Description = "My Space", MaxFileSize = 1024, MaxFilesQuantity = 100, ModifyPermittedUsers = usersWithPermissions, ReadPermittedUsers = usersWithPermissions, IsDeleted = false, CreatedAt = DateTime.Now, LastModified = DateTime.Now, Owner = localUser, Type = SpaceType.MySpace }); } else { ChangeUserIsActive(deletedUser, false); } } } var localUsers = (await _unitOfWork.Users.GetAllAsync())?.Where(lu => users.Where(u => u.id == lu.GlobalId) == null); Parallel.ForEach(localUsers, lUser => ChangeUserIsActive(lUser, true)); await _unitOfWork.SaveChangesAsync(); return(users); } catch (Exception ex) { _logger.WriteError(ex, ex.Message); return(null); } }