Exemplo n.º 1
0
        public async Task <SinglePostViewModel> GetPost(string slug)
        {
            Post _post = new Post();
            SinglePostViewModel post = new SinglePostViewModel();

            _post = await _context.Posts.Where(x => x.Slug.Equals(slug) && x.Cancelled == false).FirstOrDefaultAsync();

            if (_post != null)
            {
                _post = await _context.Posts.FirstOrDefaultAsync(p => p.PostId.Equals(_post.PostId));

                if (_post != null)
                {
                    post.PostID   = _post.PostId;
                    post.Title    = _post.Title;
                    post.Slug     = _post.Slug;
                    post.Body     = _post.Body;
                    post.Blurb    = _post.Blurb;
                    post.ImageUrl = _post.ImageUrl;
                    post.Author   = _post.Author;
                    post.Date     = _post.Date;
                    post.Tags     = _post.Tags;
                }
            }

            return(post);
        }
Exemplo n.º 2
0
        public SinglePostViewModel BuildPostViewModel(int id)
        {
            var post = _postRepository.GetPost(id);

            var model = new SinglePostViewModel()
            {
                Author       = post.Author,
                AuthorAvatar = _imageRepository.GetImageInString(post.AuthorId),
                AuthorId     = post.AuthorId,
                Content      = post.Content,
                Id           = post.Id,
                Title        = post.Title,
                PostedAt     = post.PostedAt,
                Rank         = post.Rank,
                SubTitle     = post.SubTitle
            };

            if (post.postPicture != null)
            {
                model.PostImage = _dataConverter.ConvertToString(post.postPicture.PostImageInBytes);
            }
            else
            {
                model.PostImage = string.Empty;
            }
            return(model);
        }
Exemplo n.º 3
0
        public IActionResult ViewBlog(int id)
        {
            BlogDB db = new BlogDB(_connectionString);
            SinglePostViewModel vm = new SinglePostViewModel
            {
                Blogs     = db.GetPost(id),
                Commenter = Request.Cookies["name"]
            };

            return(View(vm));
        }
Exemplo n.º 4
0
        public IActionResult MostRecent()
        {
            BlogDB db = new BlogDB(_connectionString);
            IEnumerable <BlogPost> blogPosts = db.GetBlogPosts();
            SinglePostViewModel    vm        = new SinglePostViewModel
            {
                Blogs     = blogPosts.FirstOrDefault(),
                Commenter = Request.Cookies["name"]
            };

            return(View(vm));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Single(int id)
        {
            var post = await _mediator.Send(new GetPostsById(id));

            var viewModel = new SinglePostViewModel
            {
                Name        = post.Name,
                Description = post.Description
            };

            return(View(viewModel));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, SinglePostViewModel input)
        {
            var currentPost = this.postsRepository.AllAsNoTracking()
                              .FirstOrDefault(x => x.Id == id);

            var post = new Post
            {
                Id              = input.Id,
                Title           = input.Title,
                Content         = input.Content,
                ImageUrl        = input.ImageUrl,
                NurserySchoolId = currentPost.NurserySchoolId,
                IsDeleted       = currentPost.IsDeleted,
                DeletedOn       = currentPost.DeletedOn,
                CreatedOn       = currentPost.CreatedOn,
                ModifiedOn      = input.ModifiedOn,
            };

            if (id != post.Id)
            {
                return(this.NotFound());
            }

            if (this.ModelState.IsValid)
            {
                try
                {
                    this.postsRepository.Update(post);
                    await this.postsRepository.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!this.PostExists(post.Id))
                    {
                        return(this.NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(this.RedirectToAction(nameof(this.AllPerSchool)));
            }

            return(this.View(post));
        }
Exemplo n.º 7
0
        public async Task <SinglePostViewModel> GetPostById(Guid postID)
        {
            SinglePostViewModel post = await _context.Posts.Where(x => x.PostId.Equals(postID) && x.Cancelled == false)
                                       .Select(x => new SinglePostViewModel
            {
                PostID   = x.PostId,
                Title    = x.Title,
                Slug     = x.Slug,
                Body     = x.Body,
                Blurb    = x.Blurb,
                ImageUrl = x.ImageUrl,
                Author   = x.Author,
                Date     = x.Date,
                Tags     = x.Tags
            }).FirstOrDefaultAsync();

            return(post);
        }
Exemplo n.º 8
0
        public void Given_valid_post_id_When_Delete_Returns_DeleteView()
        {
            //Given
            var id = 1;

            var model = new SinglePostViewModel();

            _postBuilder.Setup(x => x.BuildPostViewModel(It.IsAny <int>())).Returns(model);

            //When
            var result = _postController.Delete(id) as ViewResult;

            //Then

            Assert.NotNull(result);
            Assert.IsInstanceOf <SinglePostViewModel>(result.Model);
            Assert.AreEqual(String.Empty, result.ViewName);
        }
Exemplo n.º 9
0
        // GET: Post
        public ActionResult Index(string id)
        {
            var Post  = _context.Post.SingleOrDefault(p => p.PostId == id);
            var Media = _context.Media.Where(m => m.PostId == id);
            var User  = _context.Users.SingleOrDefault(u => u.UserId == Post.UserId);


            var SinglePost = new SinglePostViewModel();

            SinglePost.Post     = Post;
            SinglePost.UserName = User.Name;

            SinglePost.Media = Media.ToList();



            return(View(SinglePost));
        }
Exemplo n.º 10
0
        public void Given_valid_post_id_When_unprivileged_user_tries_Delete_Returns_DeleteView()
        {
            //Given
            var id = 1;

            _accessValidator.Setup(x => x.IsRedactor()).Returns(false);
            _accessValidator.Setup(x => x.IsAdministration()).Returns(false);

            var model = new SinglePostViewModel();

            _postBuilder.Setup(x => x.BuildPostViewModel(It.IsAny <int>())).Returns(model);

            //When
            var result = _postController.Delete(id) as RedirectToRouteResult;

            //Then

            Assert.NotNull(result);
            Assert.AreEqual("Error", result.RouteValues["controller"].ToString());
            Assert.AreEqual("Unauthorized", result.RouteValues["action"].ToString());
        }
Exemplo n.º 11
0
 public SinglePost()
 {
     this.InitializeComponent();
     ViewModel = new SinglePostViewModel();
 }
Exemplo n.º 12
0
 public virtual PartialViewResult SinglePost(SinglePostViewModel model)
 {
     return(PartialView(model));
 }