//Populates the Topics established by the user into the thoughtview model and presents it to the create page allowing for a dropdown to be created public async Task <IActionResult> CreateAsync() { var user = await _userManager.GetUserAsync(User); string userId = user.Id; ThoughtView tv = new ThoughtView(); tv.Topics = GetCategoryOptions(userId); return(View(tv)); }
public async Task <IActionResult> Create([Bind("ThoughtId,ContentText,TopicId")] ThoughtView tv) { if (ModelState.IsValid) { Thought thought = new Thought { ContentText = tv.ContentText, Topic = _context.Topics.Find(tv.TopicId), User = await _userManager.GetUserAsync(User) }; _log.LogInformation("\nSaving Thought data as... \n User: {0} \n Text: {1} \n Topic: {2}", thought.User.UserName, thought.ContentText, thought.Topic); _context.Add(thought); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tv)); }