Example #1
0
 public IActionResult Create([Bind("PostId,Title,PostContent,UserId")] InsertNewPosts post)
 {
     if (ModelState.IsValid)
     {
         _unitOfWork.PostsRepository.InsertPost(post);
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["UserId"] = new SelectList(_unitOfWork.UsersRepository.GetAllUser(), "UserId", "Username", post.UserId);
     return(View(post));
 }
 public void InsertPost([FromBody] InsertNewPosts data)
 {
     try
     {
         _unitOfWork.PostsRepository.InsertPost(data);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public void InsertPost(InsertNewPosts entity)
        {
            Posts postToSave = new Posts()
            {
                Title       = entity.Title,
                PostContent = entity.PostContent,
                CreateDate  = entity.CreateDate,
                State       = entity.State,
                UserId      = entity.UserId
            };

            this._DbContext.Posts.Add(postToSave);
            this._DbContext.SaveChanges();
        }