public ActionResult Create(PostBm post)
        {
            if (this.ModelState.IsValid)
            {
                var category = this.categoryService.GetCategory(post.CategoryName);
                this.service.AddPublication(post, category);
                return(this.RedirectToAction("All"));
            }

            return(this.View(this.GetCreatePublicationVm()));
        }
        public void CreatePost_ShouldReturnViewAndAddPost()
        {
            var bm = new PostBm()
            {
                CategoryName = "Великден"
            };

            this._controller.WithCallTo(adminPostsController => adminPostsController.Create(bm))
            .ShouldRedirectTo <AdminPostsController>(c2 => c2.All());

            Assert.AreEqual(this._repository.Set.Count, 3);
        }
        public void AddPublication(PostBm post, Category category)
        {
            var image = new Image()
            {
                Url = post.PhotoUrl
            };

            var entity = Mapper.Map <PostBm, Post>(post);

            entity.CategoryId = category.Id;
            entity.Image      = image;

            this.posts.Add(entity);
            this.posts.SaveChanges();
        }