コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Content")] Comment comment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(comment));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Content")] Comments comment)
        {
            var itemId = TempData["itemId"] as string;

            if (ModelState.IsValid)
            {
                DateTime today = DateTime.Now;

                var user = await userManager.GetUserAsync(User);

                comment.Id     = user.Id + today.ToString();
                comment.Author = user.Id;
                comment.ItemId = itemId;

                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Items", new { id = itemId }));
            }
            return(View(comment));
        }
コード例 #3
0
 public void Add(Comments comments)
 {
     _appDbContext.Add(comments);
 }
コード例 #4
0
 public void Create(Comment item)
 {
     db.Add(item);
 }