public async Task <GetPostsByProjectResponseModel> Handle(GetPostsByProjectRequestModel request, CancellationToken cancellationToken) { var posts = _messageBoard. Messages(). Where(m => m.Project.Equals(request.Project, System.StringComparison.OrdinalIgnoreCase)) .OrderBy(m => m.UserName).ThenBy(m => m.DateCreated).ToList(); List <string> response = new List <string>(); if (posts.Count > 0) { response.Add(request.Project); string prevUser = string.Empty; string currentUser = string.Empty; foreach (Message message in posts) { currentUser = message.UserName; if (currentUser != prevUser) { response.Add(currentUser); } response.Add(message.ToString()); prevUser = currentUser; } } return(await Task.Run(() => new GetPostsByProjectResponseModel { Messages = response }));; }
public async Task <GetPostsBySubscriptionResponseModel> Handle(GetPostsBySubscriptionRequestModel request, CancellationToken cancellationToken) { var projects = _projectSubscriptions.Subscriptions(). Where(s => s.UserName.Equals(request.Username, System.StringComparison.OrdinalIgnoreCase)) .OrderBy(s => s.Project).Select(s => s.Project).ToList(); var posts = _messageBoard. Messages(). Where(m => projects.Contains(m.Project)).OrderBy(m => m.DateCreated).ToList(); List <string> response = new List <string>(); if (posts.Count > 0) { foreach (Message message in posts) { response.Add($"{message.Project} - {message.UserName}: {message}"); } } return(await Task.Run(() => new GetPostsBySubscriptionResponseModel { Messages = response })); }