public ActionResult DeleteConfirmed(int id, int?ids) { ViewBag.UserType = adtype(); if (adtype() == "Admin") { SectionStudent sectionstudent = db.SectionStudents.Find(id); var sses = db.SSExams.Where(sse => sse.SectionStudent.Id == id); var ssas = db.SSAssignments.Where(ssa => ssa.SectionStudent.Id == id); foreach (SSExam sse in sses) { if (db.SSExams.Find(sse) != null) { db.SSExams.Remove(sse); } } foreach (SSAssignment ssa in ssas) { if (db.SSAssignments.Find(ssa) != null) { db.SSAssignments.Remove(ssa); } } db.SectionStudents.Remove(sectionstudent); db.SaveChanges(); return(RedirectToAction("Index", new { ids = ids })); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
protected void SubmitMarks_Click(object sender, EventArgs e) { /* this method is called when the submit mark button is clicked*/ double test; // create a dummy double var /*validate if the input can be converted to a double , this method returns true if the * result can be converted and false if not. assign the result of this method to the * createe bool var called Isvalid * * this is an input validation for the mark input */ bool IsValid = double.TryParse(Mark.Text, out test); if (IsValid) { /* if the input is valid and can be converted to double then */ GridViewRow row = detailsGridView.SelectedRow; // decalre a gridview var and assign it to the selected row in the my classes grid view SectionStudent sectionStudent = new SectionStudent(sectionId, row.Cells[1].Text.ToString()); //declare sectionstudent object and pass the section id as id and student id as a joinID sectionStudent.Grade = Mark.Text; // set the sectionStudent grade as the mark text box value sectionStudentList.Update(sectionStudent); // update the section student record with the new information } else { /* else show error message in a popup */ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", "alert('Please enter a valid mark !')", true); // show a message in a popup } }
// GET: /SectionStudent/Details/5 public ActionResult Details(int?id) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SectionStudent sectionstudent = db.SectionStudents.Find(id); if (sectionstudent == null) { return(HttpNotFound()); } return(View(sectionstudent)); }
public ActionResult Edit([Bind(Include = "Id,SectionId,StudentId")] SectionStudent sectionstudent) { ViewBag.UserType = adtype(); if (adtype() == "Admin") { if (ModelState.IsValid) { db.Entry(sectionstudent).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SectionId = new SelectList(db.Sections, "Id", "Name", sectionstudent.SectionId); ViewBag.StudentId = new SelectList(db.Students, "Id", "RegistrationNo", sectionstudent.StudentId); return(View(sectionstudent)); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
// GET: /SectionStudent/Delete/5 public ActionResult Delete(int?id, int?ids) { ViewBag.UserType = adtype(); if (adtype() == "Admin") { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SectionStudent sectionstudent = db.SectionStudents.Find(id); if (sectionstudent == null) { return(HttpNotFound()); } ViewBag.ids = ids; return(View(sectionstudent)); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
// GET: /SectionStudent/Edit/5 public ActionResult Edit(int?id) { ViewBag.UserType = adtype(); if (adtype() == "Admin") { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SectionStudent sectionstudent = db.SectionStudents.Find(id); if (sectionstudent == null) { return(HttpNotFound()); } ViewBag.SectionId = new SelectList(db.Sections, "Id", "Name", sectionstudent.SectionId); ViewBag.StudentId = new SelectList(db.Students, "Id", "RegistrationNo", sectionstudent.StudentId); return(View(sectionstudent)); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public ActionResult Create([Bind(Include = "Id,SectionId,StudentId")] SectionStudent sectionstudent, int?ids) { ViewBag.UserType = adtype(); if (adtype() == "Admin") { StudentManagmentSystem.Models.Section var = db.Sections.Find(ids); if (db.SectionStudents.Where(s => s.SectionId == ids).Count() == var.MaxCount) { ViewBag.error = "Cannot add student. Maxcount ecxeeded."; ViewBag.ids = ids; if (ids != null) { ViewBag.SectionId = new SelectList(db.Sections.Where(s => s.Id == ids), "Id", "Name", sectionstudent.SectionId); ViewBag.StudentId = new SelectList(db.Students.Where(s => db.SectionStudents.Where(ss => ss.StudentId == s.Id && ss.SectionId == ids).Count() == 0), "Id", "RegistrationNo", sectionstudent.StudentId); return(View(sectionstudent)); } ViewBag.SectionId = new SelectList(db.Sections, "Id", "Name", sectionstudent.SectionId); ViewBag.StudentId = new SelectList(db.Students, "Id", "RegistrationNo", sectionstudent.StudentId); return(View(sectionstudent)); } if (ModelState.IsValid) { db.SectionStudents.Add(sectionstudent); db.SaveChanges(); return(RedirectToAction("Index", new { ids = ids })); } ViewBag.ids = ids; if (ids != null) { ViewBag.SectionId = new SelectList(db.Sections.Where(s => s.Id == ids), "Id", "Name", sectionstudent.SectionId); ViewBag.StudentId = new SelectList(db.Students.Where(s => db.SectionStudents.Where(ss => ss.StudentId == s.Id && ss.SectionId == ids).Count() == 0), "Id", "RegistrationNo", sectionstudent.StudentId); return(View(sectionstudent)); } ViewBag.SectionId = new SelectList(db.Sections, "Id", "Name", sectionstudent.SectionId); ViewBag.StudentId = new SelectList(db.Students, "Id", "RegistrationNo", sectionstudent.StudentId); ViewBag.error = ""; return(View(sectionstudent)); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public List <SectionStudent> GetAllSectionStudentByTeacher(string year, string section) { dataAccess = new DataAccess(); string sql = "SELECT * FROM Students_Info where collegeyear ='" + year + "' and section ='" + section + "' and status= 'active'"; SqlDataReader reader = dataAccess.GetData(sql); List <SectionStudent> studentList = new List <SectionStudent>(); while (reader.Read()) { SectionStudent sectionStudent = new SectionStudent(); sectionStudent.Id = Convert.ToInt32(reader["id"]); sectionStudent.Name = reader["name"].ToString(); sectionStudent.Gender = reader["sex"].ToString(); sectionStudent.CollegeYear = reader["collegeyear"].ToString(); sectionStudent.Username = reader["username"].ToString(); sectionStudent.Section = reader["section"].ToString(); sectionStudent.Status = reader["status"].ToString(); studentList.Add(sectionStudent); } dataAccess.Dispose(); return(studentList); }
protected void EnrollMeBtn_Click(object sender, EventArgs e) { /* * This method is called when enroll me button is clicked */ /* * Declare variables and classes and instantiate them */ bool exist = false; bool alreadyExist = false; string scheduleID = ""; GridViewRow row = classListGrid.SelectedRow; // get the selected gidview row string sectionId = row.Cells[2].Text.ToString(); // get the section id string studentID = Session["User"].ToString(); // assign the student id from User session Section section = new Section(sectionId); sectionsList.Populate(section); // populate the section object Student student = new Student(studentID); studentList.Populate(student); // populate the student object // get the total hours of the student //int totalHours = scheduleList.TotalValue("Duration", "Section", "Schedule.SectionID", "Section.SectionID", "SectionStudent", "Section.SectionID", "SectionStudent.SectionID", "StudentID", student.getID()); //get the total hours of the student //This line calls the new total value with the less parameters int totalHours = scheduleList.TotalValue("Duration", "Section", "SectionID", "SectionID", "SectionStudent", "StudentID", student.getID()); int sectionTotalHours = scheduleList.TotalValue("Duration", "SectionID", sectionId); // get the total hours of the section per week if (totalHours < 20) // check if the student registerd hours are less than 20 hours { if (totalHours + sectionTotalHours > 20) { /* * if the section hours and student registerd hours are more than 20 hours then display error message in a popup * */ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", "alert('You can't SignUP for more than 20 hours !')", true); } else { scheduleList.Filter("SectionID", section.getID()); // filter schedual list by the sectionId taken from the section object foreach (Schedule schedule in scheduleList.List) { /* forEach element in the scheduleList */ // exist = scheduleList.Exist("Section", "Schedule.SectionID", "Section.SectionID", "SectionStudent", "Section.SectionID", "SectionStudent.SectionID", "Day", schedule.Day, "Time", schedule.Time, "StudentID", student.getID()); //check if the student has a class in that day and time -- //this is the 12 parameter method exist = scheduleList.Exist("Section", "SectionID", "SectionID", "SectionStudent", "Day", schedule.Day, "Time", schedule.Time, "StudentID", student.getID()); //check if the student has a class in that day and time -- this is the less parameters method scheduleID = schedule.getID(); // get the schedule id while (Convert.ToInt32(schedule.Duration) > 1 && !exist) { /* * while schedual duration more than 1 and the exit var is false */ int newTime = Convert.ToInt32(schedule.Time) + 1; // get the new time by the adding 1 to the schedule time schedule.Time = newTime.ToString(); // assign the new time to the schedule object time // exist = scheduleList.Exist("Section", "Schedule.SectionID", "Section.SectionID", "SectionStudent", "Section.SectionID", "SectionStudent.SectionID", "Day", schedule.Day, "Time", schedule.Time, "StudentID", student.getID()); //check if the student has a class in that day and time -- //this is the 12 parameter method exist = scheduleList.Exist("Section", "SectionID", "SectionID", "SectionStudent", "Day", schedule.Day, "Time", schedule.Time, "StudentID", student.getID()); //check if the student has a class in that day and time -- this is the less parameters method int duration = Convert.ToInt32(schedule.Duration) - 1; // decrease the duration by 1 schedule.Duration = duration.ToString(); // assign the new duration to the schedule object } if (exist) { /* if the exist var true make the alreadyExist var true */ alreadyExist = true; } } if (alreadyExist) { /* if the alreadyExist var true display a message saying you already have class in that time in a popup */ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", "alert('You already have a class in that time !')", true); } else { /* else */ sectionStudentList.Filter("SectionID", sectionId); // filter sectionstudentList by section id int total = sectionStudentList.List.Count; // get the count of the students that already registerd in the section total = total + 1; // add one to the count if (Convert.ToInt32(section.Capacity) >= total) { /* if the loccation capicty greater or equal to toatal var then add student to the section */ SectionStudent sectionStudent = new SectionStudent(sectionId, studentID); // create new sectionStudent object SectionStudentList sectionStudentList = new SectionStudentList(); // create new sectionStudentList sectionStudentList.Add(sectionStudent); // add the new object to the list ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Section Added", "alert('You have been Enrolled to this section !')", true); // show a message in a popup } else { /* else show a message that the section is already full */ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", "alert('The Section is Already Full !')", true); } } } } else { /* else show a messagw that you can signup for more than 20h in a popup */ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", "alert('You can't SignUP for more than 20 hours !')", true); } }