Exemplo n.º 1
0
        public Operation <Post> PublishPost(long id)
        => _auth.AuthorizeAccess(this.PermissionProfile <IPostService>(UserContext.CurrentUser()), () =>
        {
            var post = _query.GetPostById(id).ThrowIfNull("Invalid post");

            post.Status = PostStatus.Published;
            return(_pcommand
                   .Update(post)
                   .Then(opr =>
            {
                //notify everyone.
                //NOTE: this should be made asynchroneous, and possibly done with a bulk insert.
                _query.AllBitMembers().ForAll((cnt, next) =>
                {
                    _notifier.NotifyUser(new Notification
                    {
                        TargetId = next.UserId,
                        Type = NotificationType.Info,
                        Title = "New Post",
                        Message = $"Check out this <a href='/posts/index#!/details/{opr.Result.Id}'>new post</a> by Admin."
                    });
                });

                return opr;
            }));
        });