public IActionResult AllAvatars() { var avatarsFolrdPath = _pathHelper.GetPathToAvatarFolder(); var filesPath = Directory.GetFiles(avatarsFolrdPath); var models = filesPath .Where(filePath => Path.GetExtension(filePath) == ".jpg") .Select(filePath => Path.GetFileName(filePath)) .Select(fileName => new AvatarsAdminViewModel() { Url = _pathHelper.GetAvatarUrlByFileName(fileName) }).ToList(); var users = _userRepository.GetAll(); foreach (var model in models) { var user = users.SingleOrDefault(x => x.AvatarUrl == model.Url); model.UserId = user?.Id ?? -1; } return(View(models)); }