Ejemplo n.º 1
0
        public virtual async Task <IActionResult> BlogPostCreate()
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            //prepare model
            var model = await _blogModelFactory.PrepareBlogPostModelAsync(new BlogPostModel(), null);

            return(View(model));
        }
        public virtual async Task <IActionResult> BlogPost(int blogPostId)
        {
            if (!_blogSettings.Enabled)
            {
                return(RedirectToRoute("Homepage"));
            }

            var blogPost = await _blogService.GetBlogPostByIdAsync(blogPostId);

            if (blogPost == null)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //availability dates
                !_blogService.BlogPostIsAvailable(blogPost) ||
                //Store mapping
                !await _storeMappingService.AuthorizeAsync(blogPost);

            //Check whether the current user has a "Manage blog" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            var hasAdminAccess = await _permissionService.AuthorizeAsync(StandardPermissionProvider.AccessAdminPanel) && await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageBlog);

            if (notAvailable && !hasAdminAccess)
            {
                return(InvokeHttp404());
            }

            //display "edit" (manage) link
            if (hasAdminAccess)
            {
                DisplayEditLink(Url.Action("BlogPostEdit", "Blog", new { id = blogPost.Id, area = AreaNames.Admin }));
            }

            var model = new BlogPostModel();
            await _blogModelFactory.PrepareBlogPostModelAsync(model, blogPost, true);

            return(View(model));
        }
Ejemplo n.º 3
0
        public void PrepareBlogPostModelShouldRaiseExceptionIfBlogPostModelOrBlogPostIsNull()
        {
            Assert.Throws <AggregateException>(() =>
                                               _blogModelFactory.PrepareBlogPostModelAsync(null, new BlogPost(), false).Wait());

            Assert.Throws <AggregateException>(() =>
                                               _blogModelFactory.PrepareBlogPostModelAsync(null, new BlogPost(), true).Wait());

            Assert.Throws <AggregateException>(() =>
                                               _blogModelFactory.PrepareBlogPostModelAsync(new BlogPostModel(), null, false).Wait());

            Assert.Throws <AggregateException>(() =>
                                               _blogModelFactory.PrepareBlogPostModelAsync(new BlogPostModel(), null, true).Wait());
        }