public ActionResult CreatePost(Post p, string text, string text_lng) { string filename = "blog1.jpg"; if (p.upload != null) { filename = System.IO.Path.GetFileName(p.upload.FileName); p.upload.SaveAs(Server.MapPath("~/Assets/img/bg-img/" + filename)); } p.image = "/Assets/img/bg-img/" + filename; p.date = DateTime.Now; p.numOfComments = 0; p.text = text; p.text_lng = text_lng; PostBL postBL = new PostBL(); if (ModelState.IsValid) { postBL.AddPost(p); return(RedirectToAction("News", "Home")); } return(View()); }
public IActionResult CreatePost(PostCreateModel postAdd) { postAdd.PostDate = DateTime.Now; var validator = new PostCreateValidator(); if (validator.Validate(postAdd).IsValid) { var postBL = new PostBL(_uow, _mapper); var currentUserName = HttpContext.User?.Identity?.Name; if (postBL.AddPost(postAdd, currentUserName)) { return(RedirectToAction("AccountPage", "Account")); } } return(RedirectToAction("")); }
public async Task <ResultResponse <Post> > Post([FromBody] Post post) { var postBL = new PostBL(_postRepository); try { await postBL.AddPost(post); return(new ResultResponse <Post> { Success = true, Item = post }); } catch (Exception ex) { return(GetErrorResponse <Post>(ex, "Error creating post! Please try again.")); } }