public ActionResult Add()
        {
            var editData = new EditPostCategoryData
            {
                EditMode     = EditMode.Add,
                PostCategory = _postCategoryRepository.Create()
            };

            return(View("Edit", editData));
        }
        public IActionResult newpost(PostViewModel pvm)
        {
            if (!admin)
            {
                return(View("error"));
            }

            if (pvm.categoryNames == null)
            {
                ViewBag.admin      = admindisplay;
                ViewBag.user       = userdisplay;
                ViewBag.categories = _categoryrepository.GetAll();
                ViewBag.header     = ViewBag.header = _headerrepository.GetById(17);
                return(View());
            }
            _headerrepository.Create(pvm.postHeader);
            pvm.post.date      = System.DateTime.Now;
            pvm.post.headerId  = pvm.postHeader.id;
            pvm.post.viewCount = 0;
            _postrepository.Create(pvm.post);
            foreach (var item in pvm.categoryNames)
            {
                PostCategory pc = new PostCategory();
                pc.post     = pvm.post;
                pc.category = _categoryrepository.GetAll().Where(c => c.name == item).ToList()[0];
                _postcategoryrepository.Create(pc);
            }
            return(RedirectToAction("index"));
        }
        private PostCategory CreatePostCategory(Post post, string title)
        {
            var postCategory = _postCategoryRepository.Create();

            postCategory.Title = title;

            _postCategoryRepository.Save(postCategory);

            return(postCategory);
        }
Exemple #4
0
        private static string CreatePostCategory(IPostCategoryRepository repository, string title, string body)
        {
            var postCategory = repository.Create();

            postCategory.Title = title;
            postCategory.Body  = body;

            repository.Save(postCategory);

            repository.SubmitChanges();

            return(postCategory.ID);
        }
        public void PostCategory_Repository_Create()
        {
            PostCategory postCategory = new PostCategory
            {
                Name   = "Test_category",
                Alias  = "Test-category",
                Status = true
            };
            var result = _postCategoryRepository.Create(postCategory);

            _unitOfWork.SaveChanges();
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ID);
        }
 public PostCategory Add(PostCategory postCategory)
 {
     return(_postCategoryRepository.Create(postCategory));
 }