// To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Article).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArticleExists(Article.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync(int articleId, string fromUser, string toUser) { if (!ModelState.IsValid) { return(Page()); } Comment.ArticleId = articleId; IQueryable <IdentityUser> users = from u in _context.Users where u.UserName == fromUser select u; Comment.FromUser = users.FirstOrDefault().Id; users = from u in _context.Users where u.UserName == toUser select u; Comment.ToUser = users.FirstOrDefault().Id; Comment.ReleaseDate = DateTime.Now; IQueryable <Article> articles = from a in _context.Article where a.Id == articleId select a; IQueryable <int> floors = from c in _context.Comment where c.ArticleId == articles.FirstOrDefault().Id select c.Floor; if (floors.Count() != 0) { Comment.Floor = floors.Max() + 1; } else { Comment.Floor = 1; } _context.Comment.Add(Comment); await _context.SaveChangesAsync(); return(RedirectToPage("/Articles/Details", new { articleId })); }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } IQueryable <IdentityUser> users = from s in _context.Users where s.UserName == User.Identity.Name select s; Article.AuthorId = users.FirstOrDefault().Id; Article.ReleaseDate = DateTime.Now; _context.Article.Add(Article); await _context.SaveChangesAsync(); return(RedirectToPage("/Articles/Details", new { ArticleId = Article.Id })); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Article = await _context.Article.FindAsync(id); if (Article != null) { IQueryable <Comment> comments = from c in _context.Comment where c.ArticleId == Article.Id select c; foreach (Comment c in comments) { _context.Comment.Remove(c); } _context.Article.Remove(Article); await _context.SaveChangesAsync(); } return(RedirectToPage("/Index")); }