.
This commit is contained in:
parent
cfa053cfc9
commit
5e5f6a3d25
6 changed files with 26 additions and 15 deletions
|
|
@ -23,13 +23,13 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
[HttpGet("users")]
|
||||
public async Task<List<ChatUserInfo>> GetUserList()
|
||||
public IEnumerable<ChatUserInfo> GetUserList()
|
||||
{
|
||||
|
||||
var cxsQuery = dbContext.Connections.Include(c=>c.Owner).GroupBy( c => c.ApplicationUserId );
|
||||
|
||||
List<ChatUserInfo> result = new List<ChatUserInfo>();
|
||||
var cxsQuery = dbContext.Connections?.Include(c=>c.Owner).GroupBy( c => c.ApplicationUserId );
|
||||
|
||||
// List<ChatUserInfo> result = new List<ChatUserInfo>();
|
||||
if (cxsQuery!=null)
|
||||
foreach (var g in cxsQuery) {
|
||||
|
||||
var uid = g.Key;
|
||||
|
|
@ -38,12 +38,12 @@ namespace Yavsc.Controllers
|
|||
if (cxs.Count>0) {
|
||||
var user = cxs.First().Owner;
|
||||
|
||||
result.Add(new ChatUserInfo { UserName = user.UserName,
|
||||
yield return new ChatUserInfo { UserName = user.UserName,
|
||||
UserId = user.Id, Avatar = user.Avatar, Connections = cxs,
|
||||
Roles = ( await userManager.GetRolesAsync(user) ).ToArray() } );
|
||||
Roles = ( userManager.GetRolesAsync(user) ).Result.ToArray() };
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@ using System.ComponentModel.DataAnnotations;
|
|||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Newtonsoft.Json;
|
||||
using Yavsc.Models;
|
||||
using YavscLib;
|
||||
|
||||
namespace Yavsc.Model.Chat
|
||||
{
|
||||
|
||||
public class Connection
|
||||
public class Connection : IConnection
|
||||
{
|
||||
[JsonIgnore]
|
||||
public string ApplicationUserId { get; set; }
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Yavsc
|
|||
app.UseWebSockets();
|
||||
|
||||
app.UseSignalR("/api/signalr");
|
||||
|
||||
/*
|
||||
var _sockets = new ConcurrentBag<WebSocket>();
|
||||
|
||||
app.Use(
|
||||
|
|
@ -56,7 +56,7 @@ namespace Yavsc
|
|||
await next();
|
||||
}
|
||||
}
|
||||
);
|
||||
); */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ using System.Collections.Generic;
|
|||
using Yavsc.Model.Chat;
|
||||
|
||||
namespace Yavsc.ViewModels.Chat {
|
||||
public class ChatUserInfo
|
||||
public class ChatUserInfo : IChatUserInfo
|
||||
{
|
||||
|
||||
public List<Connection> Connections { get; set; }
|
||||
|
|
@ -16,4 +16,16 @@ public class ChatUserInfo
|
|||
public string[] Roles { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public interface IChatUserInfo
|
||||
{
|
||||
List<Connection> Connections { get; set; }
|
||||
string UserId { get; set; }
|
||||
|
||||
string UserName { get; set; }
|
||||
|
||||
string Avatar { get; set; }
|
||||
|
||||
string[] Roles { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue