Example #1
0
        public async Task <ActionResult <Response> > CreatePost()
        {
            try
            {
                string    title   = Request.Form["title"][0];
                string    content = Request.Form["content"][0];
                IFormFile img     = Request.Form.Files[0];
                lst = User.Claims.ToList();
                int  UserId = Convert.ToInt32(lst[0].Value);
                bool result = await post_.CreatePost(title, content, img, UserId);

                if (result)
                {
                    response.Message = "Post creado correctamente";
                    response.Status  = true;
                    response.Object  = null;
                }
                else
                {
                    response.Message = "El post no se pudo crear correctamente";
                    response.Status  = false;
                    response.Object  = null;
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = false;
                response.Object  = null;
            }
            return(response);
        }
Example #2
0
        public IActionResult PostPost([FromBody] PostEntity post)
        {
            if (post == null)
            {
                return(BadRequest());
            }

            _postService.CreatePost(post);
            return(CreatedAtAction(nameof(GetPost), new { post = post }, post));
        }
Example #3
0
        public async Task <IActionResult> Create(Post post)
        {
            if (ModelState.IsValid)
            {
                await _posts.CreatePost(post);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(post));
        }
Example #4
0
 public string CreatePost(int forumid, int userid, string posttitel)
 {
     if (posttitel.Length >= 10)
     {
         postrepository.CreatePost(forumid, posttitel, userid);
         return("Post is Created");
     }
     else
     {
         return("Titel needs a minimum of 10");
     }
 }
Example #5
0
 public async Task <ActionResult <Post> > CreatePost([FromBody] Post rawPost)
 {
     try
     {
         _logger.LogDebug($"Postlength : {rawPost.postAsMarkdown.Length}");
         var post = _postService.CreatePost(rawPost.postAsMarkdown);
         return(CreatedAtAction($"/blog/{post.postInfo.titel}", new{ id = post.PostId }));
     }
     catch (Exception e)
     {
         StringBuilder sb = new StringBuilder("An unexpected error happend calling _postService.CreatePost() with :");
         sb.AppendLine($"Post:{rawPost}");
         _logger.LogError(sb.ToString(), e);
         return(BadRequest());
     }
 }
 public IHttpActionResult Post(NewPost post)
 {
     _adapter.CreatePost(post);
     return Ok(post);
 }