private async Task <IActionResult> GetItemsAsync(IQueryable <ShareBase> query) { var items = await query .Select(s => new ShareModel() { UserName = s.UserId, Permission = (Permission)s.Permission }) .ToListAsync(); if (items.Count > 0) { var p = items.FirstOrDefault(s => s.UserName == ShareStatusService.PublicUserName); if (p != null) { items.Remove(p); } var names = await userNames.GetUserNamesAsync(items.Select(s => s.UserName).ToArray()); for (int i = 0; i < items.Count; i++) { items[i].UserName = names[i]; } items.Sort((a, b) => a.UserName.CompareTo(b.UserName)); if (p != null) { items.Insert(0, p); } } return(Ok(items)); }
public static async Task <string> GetUserNameAsync(this IUserNameProvider provider, string userId) { Ensure.NotNull(provider, "provider"); Ensure.NotNullOrEmpty(userId, "userId"); var userNames = await provider.GetUserNamesAsync(new[] { userId }); return(userNames.First()); }