This commit is contained in:
2016-12-17 14:30:45 +01:00
parent 281abd0027
commit 2a0ca73400
5 changed files with 33 additions and 34 deletions

View File

@ -6,6 +6,7 @@ using Microsoft.Data.Entity;
namespace Yavsc.Controllers
{
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Models;
using ViewModels.Chat;
@ -22,7 +23,7 @@ namespace Yavsc.Controllers
}
[HttpGet("users")]
public IEnumerable<ChatUserInfo> GetUserList()
public async Task<IEnumerable<ChatUserInfo>> GetUserList()
{
List<ChatUserInfo> result = new List<ChatUserInfo>();
var cxsQuery = dbContext.Connections?.Include(c=>c.Owner).GroupBy( c => c.ApplicationUserId );
@ -36,10 +37,13 @@ namespace Yavsc.Controllers
if (cxs !=null)
if (cxs.Count>0) {
var user = cxs.First().Owner;
if (user!=null) {
var roles = await userManager.GetRolesAsync(user);
result.Add(new ChatUserInfo { UserName = user.UserName,
UserId = user.Id, Avatar = user.Avatar, Connections = cxs,
Roles = ( userManager.GetRolesAsync(user) ).Result.ToArray() });
Roles = roles?.ToArray() });
}
}
}
return result;