public ActionResult DeleteConfirmed(int id) { StudentClassAssigningSystem studentClassAssigningSystem = db.StudentClassAssigningSystem.Find(id); db.StudentClassAssigningSystem.Remove(studentClassAssigningSystem); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: StudentClassAssigningSystems/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StudentClassAssigningSystem studentClassAssigningSystem = db.StudentClassAssigningSystem.Find(id); if (studentClassAssigningSystem == null) { return(HttpNotFound()); } return(View(studentClassAssigningSystem)); }
public ActionResult Create(StudentClassAssigningSystem studentClassAssigningSystem) { StudentCoursesBucket studentbucket = new StudentCoursesBucket(); StudentCourseRegistrationHistory studentcoursehistory = new StudentCourseRegistrationHistory(); if (ModelState.IsValid) { try { if (studentClassAssigningSystem.Comments == null) { studentClassAssigningSystem.Comments = "Comment N/A"; } studentClassAssigningSystem.AssignedDate = DateTime.Now.Date; studentClassAssigningSystem.year = DateTime.Now.Year; studentClassAssigningSystem.ClassName = (from alias in db.classes where alias.Id == studentClassAssigningSystem.ClassId select alias.ClassName).FirstOrDefault(); studentClassAssigningSystem.ProgramName = (from alias in db.programs where alias.Id == studentClassAssigningSystem.ProgramId select alias.ProgramName).FirstOrDefault(); studentClassAssigningSystem.StudentName = (from alias in db.students where alias.Id == studentClassAssigningSystem.Studentid select alias.StudentName).FirstOrDefault(); //here am updating the student model and in that model updating student recent class id by new one Students student = db.students.Find(studentClassAssigningSystem.Studentid); student.ClassId = studentClassAssigningSystem.ClassId; student.CurrentSemclass = studentClassAssigningSystem.ClassName;//here i update after student updating by program var checkingmatchentry = (from alias in db.StudentClassAssigningSystem where alias.Studentid == studentClassAssigningSystem.Studentid select alias.id).FirstOrDefault(); StudentClassAssigningSystem checkingSystem = db.StudentClassAssigningSystem.Find(checkingmatchentry); var checkingbucket = (from alias in db.StudentCoursesBucket where alias.Regid == checkingmatchentry select alias.id).FirstOrDefault(); StudentCoursesBucket coursesbucket = db.StudentCoursesBucket.Find(checkingbucket); var checkinghistory = (from alias in db.StudentCourseRegistrationHistory where alias.Regid == checkingmatchentry select alias.id).FirstOrDefault(); StudentCourseRegistrationHistory courseshistory = db.StudentCourseRegistrationHistory.Find(checkinghistory); if (checkingSystem != null) { //here deleting that record that is also exists removing that adding new record to that specific record db.StudentClassAssigningSystem.Remove(checkingSystem); db.SaveChanges(); db.StudentCoursesBucket.Remove(coursesbucket); db.SaveChanges(); db.StudentCourseRegistrationHistory.Remove(courseshistory); db.SaveChanges(); } db.StudentClassAssigningSystem.Add(studentClassAssigningSystem); db.SaveChanges(); db.Entry(studentClassAssigningSystem).GetDatabaseValues(); //here inserting record into student bucket int regid = studentClassAssigningSystem.id; studentbucket.Regid = regid; studentbucket.Studentid = studentClassAssigningSystem.Studentid; studentbucket.StudentName = studentClassAssigningSystem.StudentName; studentbucket.year = studentClassAssigningSystem.year; studentbucket.AssignedDate = studentClassAssigningSystem.AssignedDate; studentbucket.ProgramId = studentClassAssigningSystem.ProgramId; studentbucket.ClassId = studentClassAssigningSystem.ClassId; studentbucket.Comments = studentClassAssigningSystem.Comments; studentbucket.ClassName = studentClassAssigningSystem.ClassName; studentbucket.ProgramName = studentClassAssigningSystem.ProgramName; db.StudentCoursesBucket.Add(studentbucket); db.SaveChanges(); //here inserting reg courses into student bucket ends and college history inserting of couses are statrted below studentcoursehistory.Regid = regid; studentcoursehistory.Studentid = studentClassAssigningSystem.Studentid; studentcoursehistory.StudentName = studentClassAssigningSystem.StudentName; studentcoursehistory.year = studentClassAssigningSystem.year; studentcoursehistory.AssignedDate = studentClassAssigningSystem.AssignedDate; studentcoursehistory.ProgramId = studentClassAssigningSystem.ProgramId; studentcoursehistory.ClassId = studentClassAssigningSystem.ClassId; studentcoursehistory.Comments = studentClassAssigningSystem.Comments; studentcoursehistory.ClassName = studentClassAssigningSystem.ClassName; studentcoursehistory.ProgramName = studentClassAssigningSystem.ProgramName; db.StudentCourseRegistrationHistory.Add(studentcoursehistory); db.SaveChanges(); //here updating student records updated class id db.Entry(student).State = EntityState.Modified; } catch { TempData["regerror"] = "An Error Occured During The Class Registration Process Please Check Your Internet Connectivity and makesure that the Class registration Is Open "; return(RedirectToAction("Index")); } TempData["regmsg"] = "Sucessfully " + studentClassAssigningSystem.ClassName + " Is Assigned To the Student Name:" + studentcoursehistory.StudentName + "Student Id:" + studentcoursehistory.Studentid + ".The Registration Id of class/Semester Registration Is: " + studentcoursehistory.Regid; return(RedirectToAction("Index")); } ViewBag.ProgramId = new SelectList(db.programs, "Id", "ProgramName", studentClassAssigningSystem.ProgramId); ViewBag.TeacherId = db.students.Select(c => new SelectListItem { Value = c.Id.ToString(), Text = c.Id.ToString() }) .ToList(); return(View(studentClassAssigningSystem)); }