public IActionResult Create(CreateTopicBindingModel model) { if (!this.ModelState.IsValid) { return(this.View()); } return(null); }
public async Task CreateTopicAsync(CreateTopicBindingModel model) { var author = await _dbContext.Users.FirstOrDefaultAsync(a => a.UserName == model.Author); var topic = new Topic { Title = model.Title, Content = model.Content, AuthorId = author.Id, Author = (User)_dbContext.Users.FirstOrDefault(a => a.Id == author.Id), CreatedOn = model.CreatedOn }; await _dbContext.Topics.AddAsync(topic); await _dbContext.SaveChangesAsync(); }
public async Task <IActionResult> Create(CreateTopicBindingModel model) { await _service.CreateTopicAsync(model); return(RedirectToAction("Index", "Home")); }