public ActionResult Create(TopicCreateViewModel viewModel) { try { if (ModelState.IsValid) { TopicEntity topic = new TopicEntity() { DateAdded = DateTime.Now, UserId = userService.GetByPredicate(u => u.Email == User.Identity.Name).FirstOrDefault().Id, SectionId = 1, Name = viewModel.Name, Text = viewModel.Text, }; topicService.Create(topic); return RedirectToAction("Index"); } } catch(InvalidOperationException e) { logger.Error(e.Message, e); return View("Error"); } return View(); }
public ActionResult Create() { var sections = sectionService.GetAllEntities() .Select(s => new { Id = s.Id, Name = s.Name }); ViewBag.Sections = new SelectList(sections, "Id", "Name"); TopicCreateViewModel viewModel = new TopicCreateViewModel(); return View(viewModel); }