public async Task <IActionResult> Create([Bind("PostId,PostName,PostDescription,Content,TimeStamp,UserName")] Posts post)
        {
            if (ModelState.IsValid)
            {
                _context.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(post));
        }
예제 #2
0
        public async Task <IActionResult> Create(ChatRoom message)
        {
            if (ModelState.IsValid)
            {
                message.UserName = User.Identity.Name;
                var sender = await _userManager.GetUserAsync(User);

                message.UserId = sender.Id;
                await _context.Messages.AddAsync(message);

                await _context.SaveChangesAsync();

                return(Ok());
            }
            return(Error());
        }