public async Task <ActionResult> Create([Bind("FeedTitle")] Feed feed) { var user = await this._userManager.GetUserAsync(User); if (user == null) { //throw new Exception("尚未認證"); } feed.FeedCreatedDateTime = DateTime.Now; feed.FeedCreatedUser = user.Email; feed.FeedLike = 0; feed.FeedValidFlag = true; // TODO: Add insert logic here if (ModelState.IsValid) { using (var context = new VoteItDBContext()) { context.Add(feed); await context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); } return(View(feed)); }
public async Task <IActionResult> Create([Bind("FeedId,FeedTitle,FeedLike,FeedCreatedDateTime,FeedCreatedUser,FeedValidFlag")] Feed feed) { if (ModelState.IsValid) { _context.Add(feed); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(feed)); }