internal static async Task ReloadUserData() { var service = new HomeService(); var userGroups = await service.GetUserGroups(); if (userGroups.IsSuccessful) { UserData = userGroups.Data; } }
public IActionResult GetUserGroups() { var userId = ClaimsReader.GetUserId(Request); var values = context.UserGroups .Include(a => a.Group) .Where(a => a.UserId == userId) .Select(a => new { a.Relation, Value = new { a.GroupId, a.Group.Name, a.Group.Description, a.Group.IsPrivate } }).ToList(); var result = new UserGroupsWrapperDto(); result.Participant.AddRange(values.Where(a => a.Relation == GroupRelation.Owner || a.Relation == GroupRelation.User).Select(a => new UserGroupTileDto { Id = a.Value.GroupId, Name = a.Value.Name, IsOwner = a.Relation == GroupRelation.Owner, IsPrivate = a.Value.IsPrivate, Description = a.Value.Description })); result.Invited.AddRange(values.Where(a => a.Relation == GroupRelation.Invited).Select(a => new GroupTileDto { Id = a.Value.GroupId, Name = a.Value.Name })); result.Waiting.AddRange(values.Where(a => a.Relation == GroupRelation.Requesting).Select(a => new GroupTileDto { Id = a.Value.GroupId, Name = a.Value.Name })); return(Ok(result)); }