Пример #1
0
        public async Task <IActionResult> Create([Bind("Id,Title,Content,Price")] Article article)
        {
            article.CreatedAt = DateTime.Now;

            if (ModelState.IsValid)
            {
                _context.Add(article);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(article));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,Title,Content,Article_Id")] Comment comment)
        {
            comment.CreatedAt = DateTime.Now;

            if (ModelState.IsValid)
            // if (comment.Article_Id > 0)
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();

                // return RedirectToAction(nameof(Index));
                return(RedirectToAction("Details", new { controller = "Articles", id = comment.Article_Id }));
            }
            return(View(comment));
            // return RedirectToAction("Details", new { controller="Articles", id = comment.Article_Id });
        }