public ActionResult DeleteConfirmed(int id)
        {
            StudentCourseRegistrationHistory studentCourseRegistrationHistory = db.StudentCourseRegistrationHistory.Find(id);

            db.StudentCourseRegistrationHistory.Remove(studentCourseRegistrationHistory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "id,Regid,Studentid,StudentName,year,AssignedDate,ProgramId,ClassId,Comments")] StudentCourseRegistrationHistory studentCourseRegistrationHistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(studentCourseRegistrationHistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(studentCourseRegistrationHistory));
 }
        // GET: StudentCourseRegistrationHistories/Create
        //public ActionResult Create()
        //{
        //    return View();
        //}

        //// POST: StudentCourseRegistrationHistories/Create
        //// To protect from overposting attacks, please enable the specific properties you want to bind to, for
        //// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public ActionResult Create([Bind(Include = "id,Regid,Studentid,StudentName,year,AssignedDate,ProgramId,ClassId,Comments")] StudentCourseRegistrationHistory studentCourseRegistrationHistory)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        db.StudentCourseRegistrationHistory.Add(studentCourseRegistrationHistory);
        //        db.SaveChanges();
        //        return RedirectToAction("Index");
        //    }

        //    return View(studentCourseRegistrationHistory);
        //}

        // GET: StudentCourseRegistrationHistories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StudentCourseRegistrationHistory studentCourseRegistrationHistory = db.StudentCourseRegistrationHistory.Find(id);

            if (studentCourseRegistrationHistory == null)
            {
                return(HttpNotFound());
            }
            return(View(studentCourseRegistrationHistory));
        }
        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));
        }