public ActionResult ManualSignToCourse() { SearchSubjectViewModel model = new SearchSubjectViewModel(); ViewBag.AcademyID = new SelectList(repository.GetAllAcademies(), "AcademyID", "AcademyName", model.AcademyID); ViewBag.SubjectID = new SelectList(repository.GetAllSubjects(), "SubjectID", "SubjectName", model.SubjectID); return(View(model)); }
//[HttpPost] public ActionResult SignToCourse(SearchSubjectViewModel model) { if (ModelState.IsValid) { var userId = User.UserID; repository.SignUserToSubject(model, userId); } return(RedirectToAction("Courses", "User")); }
public bool SignUserToSubject(SearchSubjectViewModel model, int userId) { var user = db.Users.FirstOrDefault(x => x.UserID == userId); var subject = db.Subjects.FirstOrDefault(e => e.SubjectID == model.SubjectID && e.Academy.AcademyID == model.AcademyID && e.LectureType == model.LectureType); if (subject != null && user != null) { user.Subjects.Add(subject); subject.Users.Add(user); db.SaveChanges(); return(true); } return(false); }