Exemplo n.º 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));
 }
Exemplo n.º 2
0
 public void InsertPost([FromBody] InsertNewPosts data)
 {
     try
     {
         _unitOfWork.PostsRepository.InsertPost(data);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 3
0
        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();
        }