//GET: Trainee Course public ActionResult Create() { var trainer = (from tn in _context.Roles where tn.Name.Contains("Trainer") select tn).FirstOrDefault(); var trainerUser = _context.Users.Where(u => u.Roles.Select(us => us.RoleId).Contains(trainer.Id)).ToList(); var topic = _context.Topics.ToList(); var trainertopicVM = new AssignTrainertoTopicViewModels() { Topics = topic, Trainers = trainerUser, assignTrainertoTopics = new AssignTrainertoTopic() }; return(View(trainertopicVM)); }
public ActionResult Create(AssignTrainertoTopicViewModels model) { var trainer = (from tn in _context.Roles where tn.Name.Contains("Trainer") select tn).FirstOrDefault(); var trainerUser = _context.Users.Where(u => u.Roles.Select(us => us.RoleId).Contains(trainer.Id)).ToList(); var topic = _context.Topics.ToList(); if (ModelState.IsValid) { _context.AssignTrainertoTopics.Add(model.assignTrainertoTopics); _context.SaveChanges(); return(RedirectToAction("Index")); } var trainertopicVM = new AssignTrainertoTopicViewModels() { Topics = topic, Trainers = trainerUser, assignTrainertoTopics = new AssignTrainertoTopic() }; return(View(trainertopicVM)); }