Example #1
0
        public bool CreatePost(ref Post post, ref string message)
        {
            var result = true;

            if (string.IsNullOrEmpty(post.PostContent))
            {
                message = "Content cannot be empty";
                result  = false;
            }

            else
            {
                try
                {
                    var postBDO = new PostBDO();
                    TranslatePostDTOtoPostBDO(post, postBDO);
                    result = postLogic.CreatePost(ref postBDO, ref message);
                }
                catch (Exception e)
                {
                    var msg = e.Message;
                    throw new FaultException <PostFault>(new PostFault(msg), msg);
                }
            }
            return(result);
        }
Example #2
0
        public void CreatePost_Expects_True()
        {
            _auraLogic.NewAura();
            Category category = _categoryLogic.GetCategoryById(1);
            User     user     = _userLogic.GetUserById(1);
            Post     post     = new Post()
            {
                Title    = "let's go bois", Content = "gamertime", PostDate = DateTime.Now, User = user,
                Category = category, Aura = _mockAuraRepo.AuraList.LastOrDefault()
            };

            _postLogic.CreatePost(post);

            Assert.AreEqual(4, _mockPostRepo.PostList.Count());
        }
Example #3
0
        public IActionResult Index(SubmitPageViewModel model)
        {
            if (ModelState.IsValid)
            {
                Post post = new Post {
                    Title = model.Title, Content = model.Content, Category = new Category()
                    {
                        CategoryId = model.CategoryId
                    }, User = new User()
                    {
                        UserId = (int)HttpContext.Session.GetInt32("UserId")
                    }
                };

                _auraLogic.NewAura();
                _postLogic.CreatePost(post);
                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }