Beispiel #1
0
        public async Task <HttpResponseMessage> UpdateAsync(ContentActivity contentActivity)
        {
            var node        = contentActivity.Node;
            var httpContext = _httpContextAccessor.HttpContext;
            var userId      = httpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (node.CreatedBy != userId)
            {
                var allowed = await _securityService.IsAllowedAsync(
                    httpContext.User, node.Module, node.Type, Actions.Edit);

                if (!allowed)
                {
                    throw new Exception("User is not allowed to perform the action.");
                }
            }

            node.LastUpdatedBy   = userId;
            node.LastUpdatedDate = DateTimeOffset.UtcNow.ToString("s");
            await _nodeService.UpdateAsync(node);

            var message = contentActivity.Message;
            await _activityService.AddAsync(node.Id, message, userId);

            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
        }
Beispiel #2
0
        protected async Task SubmitAsync()
        {
            Channel.Slug = Channel.Name.ToSlug();
            var existingChannel = await NodeService.GetBySlugAsync(
                Constants.VideosModule,
                Constants.ChannelType,
                Channel.Slug,
                true);

            if (existingChannel == null)
            {
                var contentActivity = new ContentActivity()
                {
                    Node    = Channel,
                    Message = $"Edited a video channel: {Channel.Name}."
                };
                await NodeService.UpdateAsync(contentActivity);

                NavigationManager.NavigateTo($"videos/{Channel.Slug}");
            }
            else
            {
                ValidationMessage = "A similar name already exists.";
            }
        }
Beispiel #3
0
        protected async Task SubmitAsync()
        {
            var existingCategory = await NodeService.GetBySlugAsync(
                Constants.ArticlesModule,
                Constants.CategoryType,
                Category.Slug,
                true);

            if (existingCategory == null)
            {
                var contentActivity = new ContentActivity()
                {
                    Node    = Category,
                    Message = $"Added a new article category: {Category.Name}."
                };
                var response = await NodeService.AddAsync(contentActivity);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    NavigationManager.NavigateTo($"articles/{Category.Slug}");
                }
                else
                {
                    ValidationMessage = "Unable to save.";
                }
            }
            else
            {
                ValidationMessage = "A similar name already exists.";
            }
        }
Beispiel #4
0
        protected async Task SubmitAsync()
        {
            Forum.ParentId = ParentId;
            var existingForum = await NodeService.GetBySlugAsync(
                Constants.ForumsModule,
                Constants.ForumType,
                Forum.Name,
                true);

            if (existingForum == null)
            {
                var contentActivity = new ContentActivity()
                {
                    Node    = Forum,
                    Message = $"Added a new forum: {Forum.Name}."
                };
                await NodeService.AddAsync(contentActivity);

                NavigationManager.NavigateTo($"forum/{Forum.Slug}");
            }
            else
            {
                ValidationMessage = "A similar title already exists.";
            }
        }
        protected async Task SubmitAsync()
        {
            if (!string.IsNullOrEmpty(Comment.Content) &&
                Comment.Content != PreviousComment)
            {
                if (Id == null)
                {
                    Comment.PostId = PostId;
                    var contentActivity = new ContentActivity()
                    {
                        Node    = Comment,
                        Message = $"Added a new forum comment: {Comment.Snippet}"
                    };
                    await NodeService.AddAsync(contentActivity);
                }
                else
                {
                    var contentActivity = new ContentActivity()
                    {
                        Node    = Comment,
                        Message = $"Updated a new forum comment: {Comment.Snippet}"
                    };
                    await NodeService.UpdateAsync(contentActivity);
                }
                await OnSave.InvokeAsync(Comment);

                PreviousComment = Comment.Content;
                Comment.Content = string.Empty;
            }
        }
Beispiel #6
0
        protected async Task SubmitAsync()
        {
            Article.Slug = Article.Title.ToSlug();
            var existingArticle = await NodeService.GetBySlugAsync(
                Constants.ArticlesModule,
                Constants.ArticleType,
                Article.Slug,
                true);

            if (existingArticle == null || existingArticle.Id == Article.Id)
            {
                var contentActivity = new ContentActivity()
                {
                    Node    = Article,
                    Message = $"Updated an article: {Article.Title}."
                };
                await NodeService.UpdateAsync(contentActivity);

                NavigationManager.NavigateTo($"article/{Article.Slug}", true);
            }
            else
            {
                ValidationMessage = "A similar title already exists.";
            }
        }
Beispiel #7
0
        protected async Task SubmitAsync()
        {
            Post.Slug = Post.Title.ToSlug();
            var existingPost = await NodeService.GetBySlugAsync(
                Constants.BlogsModule,
                Constants.PostType,
                Post.Slug,
                true);

            if (existingPost == null)
            {
                var contentActivity = new ContentActivity()
                {
                    Node    = Post,
                    Message = $"Added a new post: {Post.Title}."
                };
                await NodeService.AddAsync(contentActivity);

                NavigationManager.NavigateTo($"blog/post/{Post.Slug}");
            }
            else
            {
                ValidationMessage = "A similar name already exists.";
            }
        }
Beispiel #8
0
        protected async Task SubmitAsync()
        {
            Blog.Slug = Blog.Name.ToSlug();
            var existingBlog = await NodeService.GetBySlugAsync(
                Constants.BlogsModule,
                Constants.BlogType,
                Blog.Slug,
                true);

            if (existingBlog == null || existingBlog.Id == Blog.Id)
            {
                var contentActivity = new ContentActivity()
                {
                    Node    = Blog,
                    Message = $"Updated blog: {Blog.Name}."
                };
                await NodeService.UpdateAsync(contentActivity);

                NavigationManager.NavigateTo($"blog/{Blog.Slug}", true);
            }
            else
            {
                ValidationMessage = "A similar name already exists.";
            }
        }
Beispiel #9
0
        public async Task <HttpResponseMessage> AddAsync(ContentActivity contentActivity)
        {
            var response = await AuthorizedHttpClient.PostAsJsonAsync <ContentActivity>(API_URL, contentActivity);

            var id = await response.Content.ReadAsStringAsync();

            contentActivity.Node.Id = id;

            return(response);
        }
Beispiel #10
0
        protected async Task SubmitAsync()
        {
            var contentActivity = new ContentActivity()
            {
                Node    = Topic,
                Message = $"Added a new forum topic: {Topic.Snippet}"
            };
            await NodeService.AddAsync(contentActivity);

            NavigationManager.NavigateTo($"forum/topic/{Topic.Id}");
        }
Beispiel #11
0
        protected async Task SubmitAsync()
        {
            var contentActivity = new ContentActivity()
            {
                Node    = Topic,
                Message = $"Updated a new forum topic."
            };
            await NodeService.UpdateAsync(contentActivity);

            NavigationManager.NavigateTo($"forum/topic/{Topic.Id}", true);
        }
Beispiel #12
0
        protected async Task SubmitAsync()
        {
            var contentActivity = new ContentActivity()
            {
                Node    = Config,
                Message = $"Updated Articles description."
            };
            await NodeService.UpdateAsync(contentActivity);

            NavigationManager.NavigateTo("/articles", true);
        }
Beispiel #13
0
        protected async Task SubmitAsync()
        {
            var contentActivity = new ContentActivity()
            {
                Node    = Forum,
                Message = $"Updated a forum: {Forum.Name}."
            };
            await NodeService.UpdateAsync(contentActivity);

            NavigationManager.NavigateTo($"forum/{Forum.Slug}", true);
        }
Beispiel #14
0
        protected async Task SubmitAsync()
        {
            var contentActivity = new ContentActivity()
            {
                Node    = Profile,
                Message = $"Created the profile: {Profile.Slug}."
            };
            await NodeService.AddAsync(contentActivity);

            NavigationManager.NavigateTo($"profile/in/{Profile.Slug}");
        }
Beispiel #15
0
        protected async Task SubmitAsync()
        {
            await VideoService.SetVideoAttributesAsync(Video);

            var contentActivity = new ContentActivity()
            {
                Node    = Video,
                Message = $"Added a new video: {Video.Url}."
            };
            await NodeService.AddAsync(contentActivity);

            if (SetAsChannelThumbnail)
            {
                Channel.ThumbnailUrl = Video.ThumbnailUrl;
                contentActivity      = new ContentActivity()
                {
                    Node    = Channel,
                    Message = $"Updated a video channel: {Channel.Name}."
                };
                await NodeService.UpdateAsync(contentActivity);
            }
            NavigationManager.NavigateTo($"video/{Video.Id}");
        }
        protected async Task SubmitAsync()
        {
            if (string.IsNullOrEmpty(Id))
            {
                Post.TopicId = TopicId;
                var contentActivity = new ContentActivity()
                {
                    Node    = Post,
                    Message = $"Added a new forum post: {Post.Snippet}"
                };
                await NodeService.AddAsync(contentActivity);
            }
            else
            {
                var contentActivity = new ContentActivity()
                {
                    Node    = Post,
                    Message = $"Updated a forum post: {Post.Snippet}"
                };
                await NodeService.UpdateAsync(contentActivity);
            }

            await OnSave.InvokeAsync(Post);
        }
Beispiel #17
0
        protected async Task SubmitAsync()
        {
            Blog.Slug = Blog.Name.ToSlug();
            var existingArticle = await NodeService.GetBySlugAsync(
                Constants.BlogsModule,
                Constants.BlogType,
                Blog.Slug);

            if (existingArticle == null)
            {
                var contentActivity = new ContentActivity()
                {
                    Node    = Blog,
                    Message = $"Added a new blog: {Blog.Name}."
                };
                await NodeService.AddAsync(contentActivity);

                NavigationManager.NavigateTo($"blog/{Blog.Slug}");
            }
            else
            {
                ValidationMessage = "A similar name already exists.";
            }
        }
        public async Task <IActionResult> PostAsync(ContentActivity contentActivity)
        {
            var node   = contentActivity.Node;
            var userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            var allowed = await _securityService.IsAllowedAsync(
                HttpContext.User,
                node.Module,
                node.Type,
                Actions.Add);

            if (!allowed)
            {
                throw new Exception("User is not allowed to perform the action.");
            }

            node.CreatedBy = userId;
            var id = await _nodeService.AddAsync(node);

            var message = contentActivity.Message;
            await _activityService.AddAsync(id, message, userId);

            return(Ok(id));
        }
Beispiel #19
0
        protected async Task SubmitAsync()
        {
            var existingCategory = await NodeService.GetBySlugAsync(
                Constants.ArticlesModule,
                Constants.CategoryType,
                Category.Slug,
                true);

            if (existingCategory == null || existingCategory.Id == Category.Id)
            {
                var contentActivity = new ContentActivity()
                {
                    Node    = Category,
                    Message = $"Added a new article category: {Category.Name}."
                };
                await NodeService.UpdateAsync(contentActivity);

                NavigationManager.NavigateTo($"articles/{Category.Slug}", true);
            }
            else
            {
                ValidationMessage = "A similar name already exists.";
            }
        }
Beispiel #20
0
 public async Task <HttpResponseMessage> UpdateAsync(ContentActivity contentActivity)
 {
     return(await AuthorizedHttpClient.PutAsJsonAsync <ContentActivity>(API_URL, contentActivity));
 }