public IActionResult Create([Bind("Id,Title,Perex,Content,AuthorId,CreatedAt")] Post post) { if (ModelState.IsValid) { _context.Add(post); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(post)); }
public async Task <IActionResult> Post([Bind("ID, Title, Author, Content")] Post post) { if (ModelState.IsValid) { _context.Add(post); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(GetAll))); } return(View(post)); }
public async Task <ActionResult> Create(Post post) { // Manual Requests body to object binding caused by TS & C# dates incompatibility. try { string postObject; using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8)) { postObject = await reader.ReadToEndAsync(); } post = JsonConvert.DeserializeObject <Post>(postObject); // according to TypeScript Date and C# DateTime incompatibility, have to set the creationDate on the server-side post.PublicationDate = DateTime.Now; _ctx.Add(post); } catch (Exception ex) { throw ex; } return(Ok(post)); }