public int Create(Post post) { if (post.Description == null || post.Title == null) { throw new Exception("All fields must be filled in"); } return(_post.Create(post)); }
public HttpResponseMessage Ins(PostInsDTO dto) { if (dto != null) { using (repo) repo.Create(dto.Content, dto.Rating, dto.Views, dto.UserId, dto.Title); return(Request.CreateResponse(HttpStatusCode.OK)); } return(Request.CreateResponse(HttpStatusCode.NoContent)); }
public async Task <IActionResult> Create([FromBody] Post post) { try { if (post != null) { post.Id = User.FindFirst(ClaimTypes.NameIdentifier).Value; await _postRepo.Create(post).ConfigureAwait(false); return(Ok()); } return(BadRequest()); } catch (Exception e) { throw new Exception(e.Message); } }
public IActionResult Create(CreatePostVM createPostModel) { if (!ModelState.IsValid) { return(View(createPostModel)); } var postModel = new PostModel() { AuthorUser = _userRepo.GetById(User.Id()), Title = createPostModel.Title, Body = createPostModel.Body, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; _postRepo.Create(postModel); return(RedirectToAction(nameof(Index))); }