Ejemplo n.º 1
0
        public ActionResult Create(PostViewModel post)
        {
            if (ModelState.IsValid)
            {
                var postDto = Mapper.Map <PostDto>(post);
                _postManager.AddPost(postDto);
                return(RedirectToAction("Index"));
            }

            return(View());
        }
Ejemplo n.º 2
0
        public IActionResult AddPost([FromBody] Post post, [FromQuery] string lang)
        {
            if (string.IsNullOrWhiteSpace(post.Content))
            {
                return(Ok());
            }

            if (!postManager.AddPost(User.Identity.Name, post.Content))
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, Resources.Errors.PostNotAdded));
            }
            return(Ok());
        }
Ejemplo n.º 3
0
        public void CanAddPost()
        {
            _testPost.Content     = "Blah.";
            _testPost.CreatedDate = DateTime.Now;
            _testPost.PublishDate = DateTime.Now;
            _testPost.Title       = "Test post";
            _testPost.Author      = new Author {
                Id = "8b1603b6-0d7a-46d8-a2eb-df064216a29a"
            };

            _postManager.AddPost(_testPost, new[] { "#neato" }, new[] { ".NET" }, "Approved");

            Assert.AreEqual(7, _postManager.GetAllByStatus("Approved").Data.Count);
        }
Ejemplo n.º 4
0
 public JsonResult SavePost(string data)
 {
     try
     {
         SysPost model = Newtonsoft.Json.JsonConvert.DeserializeObject <SysPost>(data);
         if (model.PostId == 0)
         {
             model.CreateTime = DateTime.Now;
             model.CreateUser = 0;
             model.TenantId   = CurrentTenant.TenantId;
             model.PostCode   = model.PostName;
             //新增
             _postManager.AddPost(model);
         }
         else
         {
             //修改
             SysPost post = _postManager.GetPostById(model.PostId);
             if (post == null)
             {
                 return(Json(new { result = 0, content = RetechWing.LanguageResources.TenantUI.TenantPost.NotFound }, JsonRequestBehavior.AllowGet));
             }
             if (post.TenantId != CurrentTenant.TenantId)
             {
                 return(Json(new { result = 0, content = RetechWing.LanguageResources.TenantUI.TenantPost.NotFound }, JsonRequestBehavior.AllowGet));
             }
             var childIds = new List <int>();
             GetChildPostIds(model.PostId, _postManager.GetAllPost(CurrentTenant.TenantId), childIds);
             childIds.Add(model.PostId);
             if (childIds.Contains(model.ParentId))
             {
                 return(Json(new { result = 0, content = RetechWing.LanguageResources.TenantUI.TenantPost.CanNotBeSub }, JsonRequestBehavior.AllowGet));
             }
             post.ParentId    = model.ParentId;
             post.PostName    = model.PostName;
             post.PostCode    = model.PostName;
             post.Description = model.Description;
             _postManager.UpdatePost(post);
             if (post.DeptId != model.DeptId)
             {
                 _postManager.UpdatePostDeptId(model.DeptId, childIds.ToArray());
             }
         }
         return(Json(new { result = 1, content = RetechWing.LanguageResources.Common.SaveSuccess }, JsonRequestBehavior.AllowGet));
     }
     catch
     {
         return(Json(new { result = 0, content = RetechWing.LanguageResources.Common.SaveFailed }, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 5
0
        public void Test_PutPost()
        {
            //Arrange
            Mock <DbSet <Post> > dbSetMock = new Mock <DbSet <Post> >();

            _contextMoq.Setup(x => x.Posts).Returns(dbSetMock.Object);
            var dto = new PostDto {
                Title = "test"
            };

            //Act
            _manager.AddPost(dto);

            //Assert
            _contextMoq.Verify(x => x.SaveChanges(), Times.Once);
            dbSetMock.Verify(x => x.Add(It.IsAny <Post>()), Times.Once);
        }
Ejemplo n.º 6
0
        public IActionResult AddPost([FromBody] PostRequest postRequest)
        {
            if (!postRequest.PostTags.All(t => _tagManager.TagExists(t)))
            {
                return(BadRequest("Post contains nonexistent tag(s)."));
            }

            var post = _mapper.Map <Post>(postRequest);

            post.AuthorId = _userManager.GetUserId(HttpContext.User);

            _postManager.AddPost(post);

            var response = _mapper.Map <PostResponse>(post);

            return(CreatedAtAction(nameof(GetPost), new { id = post.Id }, response));
        }
Ejemplo n.º 7
0
 public IActionResult AddPost(string newPost)
 {
     try
     {
         var user   = _userManager.GetUserAsync(User).Result;
         var result = _postManager.AddPost(new Post()
         {
             Content = newPost, PostedDate = DateTime.Now, User = user
         });
         return(Ok(new PostDto {
             Content = result.Entity.Content, User = $"{result.Entity.User.Name} {result.Entity.User.Surname}", PostedDate = result.Entity.PostedDate, Id = result.Entity.Id
         }));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 8
0
        // POST: api/Post
        public HttpResponseMessage Post(PostCategoryTagVM viewModel) //(Post blogPost, string tags)//, string[] categories)//(JObject data)
        {
            Post blogPost = new Post()
            {
                Title  = viewModel.Title,
                Author = new Author()
                {
                    Id = User.Identity.GetUserId(), Name = User.Identity.Name
                },
                CreatedDate = DateTime.Now,
                PublishDate = viewModel.PublishDate,
                ExpireDate  = viewModel.ExpireDate,
                Content     = viewModel.Content
            };
            Response <Post> response = _postManager.AddPost(blogPost, viewModel.TagList, viewModel.CategoryList, viewModel.Status);

            return(Request.CreateResponse(HttpStatusCode.Created, response.Data));
        }