public async Task <MakeSubscriptionResponseModel> Handle(MakeSubscriptionRequestModel request, CancellationToken cancellationToken)
        {
            var result = new MakeSubscriptionResponseModel
            {
                IsSuccess = true,
            };

            Subscription newSubscription = new Subscription {
                Project = request.Project, UserName = request.UserName
            };
            await Task.Run(() => _projectSubscriptions.Subscriptions().Add(newSubscription));

            return(result);
        }
示例#2
0
        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 }));
        }