Exemple #1
0
 public ActionResult DeleteConfirm(SubjectViewModels model)
 {
     using (JournalContext db = new JournalContext())
     {
         Subject subject = db.Subjects.Find(model.ID);
         db.Subjects.Remove(subject);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
Exemple #2
0
 // GET: TeacherSubject/Details/5
 public ActionResult Details(Guid id)
 {
     using (JournalContext db = new JournalContext())
     {
         Subject           teacherSubject = db.Subjects.Find(id);
         SubjectViewModels model          = new SubjectViewModels();
         model.TeacherID           = teacherSubject.TeacherID;
         model.SubjectTypeID       = teacherSubject.SubjectTypeID;
         model.SelectedTeacher     = db.Users.Where(c => c.ID == model.TeacherID).Select(c => c.FirstName + " " + c.LastName).FirstOrDefault();
         model.SelectedSubjectType = db.SubjectTypes.Where(c => c.ID == model.SubjectTypeID).Select(c => c.Name).FirstOrDefault();
         return(View(model));
     }
 }
Exemple #3
0
 public ActionResult Create()
 {
     using (JournalContext db = new JournalContext())
     {
         var TeacherRoll         = Guid.Parse(Roles.Teacher);
         SubjectViewModels model = new SubjectViewModels();
         model.Teachers = db.Users.Where(c => c.UserRollID == TeacherRoll).Select(user => new SelectListItem()
         {
             Value = user.ID.ToString(), Text = user.FirstName + " " + user.LastName
         }).ToList();
         model.SubjectTypes = db.SubjectTypes.Select(subjectType => new SelectListItem()
         {
             Value = subjectType.ID.ToString(), Text = subjectType.Name
         }).ToList();
         return(View(model));
     }
 }
Exemple #4
0
 public ActionResult Delete(Guid id)
 {
     using (JournalContext db = new JournalContext())
     {
         Subject           subject = db.Subjects.Find(id);
         SubjectViewModels model   = new SubjectViewModels();
         model.ID                  = subject.ID;
         model.SubjectTypeID       = subject.SubjectTypeID;
         model.TeacherID           = subject.TeacherID;
         model.SelectedTeacher     = db.Users.Where(c => c.ID == model.TeacherID).Select(c => c.FirstName + " " + c.LastName).FirstOrDefault();
         model.SelectedSubjectType = db.SubjectTypes.Where(c => c.ID == model.SubjectTypeID).Select(c => c.Name).FirstOrDefault();
         if (model == null)
         {
             return(HttpNotFound());
         }
         return(View(model));
     }
 }
Exemple #5
0
 public ActionResult Edit(Guid id)
 {
     using (JournalContext db = new JournalContext())
     {
         SubjectViewModels model          = new SubjectViewModels();
         Subject           teacherSubject = db.Subjects.Find(id);
         var TeacherRoll = Guid.Parse(Roles.Teacher);
         model.ID            = teacherSubject.ID;
         model.TeacherID     = teacherSubject.TeacherID;
         model.SubjectTypeID = teacherSubject.SubjectTypeID;
         model.Teachers      = db.Users.Where(c => c.UserRollID == TeacherRoll).Select(user => new SelectListItem()
         {
             Value = user.ID.ToString(), Text = user.FirstName + " " + user.LastName
         }).ToList();
         model.SubjectTypes = db.SubjectTypes.Select(subjectType => new SelectListItem()
         {
             Value = subjectType.ID.ToString(), Text = subjectType.Name
         }).ToList();
         model.SelectedTeacher     = db.Users.Where(c => c.ID == model.TeacherID).Select(c => c.FirstName + " " + c.LastName).FirstOrDefault();
         model.SelectedSubjectType = db.SubjectTypes.Where(c => c.ID == model.SubjectTypeID).Select(c => c.Name).FirstOrDefault();
         return(View(model));
     }
 }
Exemple #6
0
 public ActionResult Create(SubjectViewModels model)
 {
     using (JournalContext db = new JournalContext())
     {
         if (ModelState.IsValid)
         {
             var TeacherRoll = Guid.Parse(Roles.Teacher);
             model.Teachers = db.Users.Where(c => c.UserRollID == TeacherRoll).Select(user => new SelectListItem()
             {
                 Value = user.ID.ToString(), Text = user.FirstName + " " + user.LastName
             }).ToList();
             model.SubjectTypes = db.SubjectTypes.Select(subjectType => new SelectListItem()
             {
                 Value = subjectType.ID.ToString(), Text = subjectType.Name
             }).ToList();
             Subject Subject = (Subject)model;
             Subject.ID = Guid.NewGuid();
             db.Subjects.Add(Subject);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(model));
     }
 }