예제 #1
0
 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));
 }
예제 #2
0
 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);
            }
        }
예제 #4
0
        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)));
        }