public ActionResult Create(StudentTB studentTB) { try { using (DBModels dBModels = new DBModels()) { dBModels.StudentTBs.Add(studentTB); if (ModelState.IsValid) { dBModels.SaveChanges(); return(RedirectToAction("Loginpage", "Student")); } else { return(new JsonResult { Data = "Student not Registered" }); } } //return RedirectToAction("Loginpage", "Student"); } catch { return(View()); } }
public ActionResult Edit(int id) { using (DBmodel dBModels = new DBmodel()) { StudentTB temp = dBModels.StudentTBs.Where(x => x.sid == id).FirstOrDefault(); Studentmodel model = new Studentmodel(); model.fullname = temp.fullname; model.gender = temp.gender; model.address = temp.address; model.email = temp.email; model.grade = temp.grade; model.parentname = temp.parentname; model.parenttpnum = temp.parenttpnum; model.password = temp.password; model.school = temp.school; model.sid = temp.sid; model.subject = temp.subject; model.tpnum = temp.tpnum; model.username = temp.username; List <GradeList> grades = dBModels.GradeLists.ToList(); List <subject> subjects = dBModels.subjects.ToList(); ViewBag.Grades = new SelectList(grades, "Grade", "Grade"); ViewBag.Subjects = new SelectList(subjects, "subject1", "subject1"); return(View(model)); } }
public ActionResult Edit(int id, StudentTB studentTB) { try { using (DBModels dBModels = new DBModels()) { dBModels.Entry(studentTB).State = System.Data.Entity.EntityState.Modified; dBModels.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, Studentmodel temp) { try { StudentTB model = new StudentTB(); using (DBmodel dBModels = new DBmodel()) { model.fullname = temp.fullname; model.gender = temp.gender; model.address = temp.address; model.email = temp.email; model.grade = temp.grade; model.parentname = temp.parentname; model.parenttpnum = temp.parenttpnum; model.password = temp.password; model.school = temp.school; model.sid = id; model.subject = temp.subject; model.tpnum = temp.tpnum; model.username = temp.username; dBModels.Entry(model).State = System.Data.Entity.EntityState.Modified; dBModels.SaveChanges(); } if (Session["Role"].ToString().Contains("Admin")) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Details", new { id = model.sid })); } } catch { DBmodel dBModels = new DBmodel(); List <GradeList> grades = dBModels.GradeLists.ToList(); List <subject> subjects = dBModels.subjects.ToList(); ViewBag.Grades = new SelectList(grades, "Grade", "Grade"); ViewBag.Subjects = new SelectList(subjects, "subject1", "subject1"); return(View()); } }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here using (DBModels dBModels = new DBModels()) { StudentTB studentTB = dBModels.StudentTBs.Where(x => x.sid == id).FirstOrDefault(); dBModels.StudentTBs.Remove(studentTB); dBModels.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
/// <summary> /// GET:Add Student /// </summary> /// <returns></returns> public ActionResult Add_student_fee(int id) { string date = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt"); string month = DateTime.Now.ToString("MMMM"); DBmodel payrollentities = new DBmodel(); StudentTB studentTB = payrollentities. StudentTBs.SingleOrDefault(x => x.sid == id); StudentFeeView studentFeeView = new StudentFeeView(); studentFeeView.StudentID = studentTB.sid; studentFeeView.Name = studentTB.fullname; studentFeeView.Subject = studentTB.subject; studentFeeView.Month = month; studentFeeView.Date_Time = date; return(View(studentFeeView)); }
public ActionResult Details(int id) { using (DBmodel dBModels = new DBmodel()) { StudentTB temp = dBModels.StudentTBs.Where(x => x.sid == id).FirstOrDefault(); Studentmodel model = new Studentmodel(); model.fullname = temp.fullname; model.gender = temp.gender; model.address = temp.address; model.email = temp.email; model.grade = temp.grade; model.parentname = temp.parentname; model.parenttpnum = temp.parenttpnum; model.password = temp.password; model.school = temp.school; model.sid = temp.sid; model.subject = temp.subject; model.tpnum = temp.tpnum; model.username = temp.username; return(View(model)); } }
protected void Button3_Click(object sender, EventArgs e) { try { //using (UserDatabaseEntities dbcon = new UserDatabaseEntities()) //{ AppointmentTB myStudent = new AppointmentTB(); // create a new row //query for student user name StudentTB student = (from x in dbcontext.StudentTBs.Local where x.StudentUserName.Equals(User.Identity.Name.ToString()) select x).First(); myStudent.StudentID = student.StudentID; //take studentID from StudentTB myStudent.AdvisorID = student.StudentAdvisorID; //take advisorID from StudentTB myStudent.AppointmentDate = Convert.ToDateTime(Label2.Text); // add date int hour = //take hour from dropdown2 Convert.ToInt32(DropDownList2.SelectedValue.ToString()); int min = //take minute from dropdown3 Convert.ToInt32(DropDownList3.SelectedValue.ToString()); //add hour & min from above myStudent.AppointmentTime = new TimeSpan(hour, min, 0); myStudent.AppointmentReason = TextBox2.Text; //add reason from textbox2 /* * AppointmentTB existingAppt = (from x in dbcontext.AppointmentTBs.Local //this only works for displaying the... * where x.AppointmentDate == myStudent.AppointmentDate //else statement when there... * && x.AppointmentTime == myStudent.AppointmentTime //is another appointment * && x.AdvisorID == myStudent.AdvisorID * && x.StudentID == myStudent.StudentID * select x).First(); * // add row to the table * if ( existingAppt == null) //will have to take out the if else statement until we figure it out????? * { * dbcontext.AppointmentTBs.Add(myStudent); * dbcontext.SaveChanges(); * } * else * { * Label4.Text = "Sorry, this time has already been reserved."; * }*/ try { AppointmentTB existingAppt = (from x in dbcontext.AppointmentTBs.Local //this only works for displaying the... where x.AppointmentDate == myStudent.AppointmentDate && //else statement when there... x.AppointmentTime == myStudent.AppointmentTime && //is another appointment x.AdvisorID == myStudent.AdvisorID && x.StudentID == myStudent.StudentID select x).First(); // add row to the table if (existingAppt == null) //will have to take out the if else statement until we figure it out????? { //this works now, but I'm just going to leave this if section in to show what it is supposed to do dbcontext.AppointmentTBs.Add(myStudent); dbcontext.SaveChanges(); } else { //dbcontext.AppointmentTBs.Add(myStudent); //dbcontext.SaveChanges(); Label4.Text = "Sorry, this time has already been reserved."; } } catch (Exception) { //MessageBox.Show(ex.Message); dbcontext.AppointmentTBs.Add(myStudent); dbcontext.SaveChanges(); Label4.Text = ""; } //dbcontext.AppointmentTBs.Add(myStudent); //dbcontext.SaveChanges(); //clear data //TextBox1.Text = ""; //TextBox2.Text = ""; //show new data in the gridview //dbcontext.AppointmentTBs.Load(); //var result = from x in dbcontext.AppointmentTBs.Local // select x; //show data in the Gridview1 //GridView4.DataSource = result.ToList(); //GridView4.DataBind(); ReloadAppointments(); } catch { Label4.Text = "Please select a date from the calendar."; } //}// add time }
public ActionResult Create(Studentmodel temp) { try { using (DBmodel dBModels = new DBmodel()) { if (dBModels.StudentTBs.Any(m => m.username == temp.username) || dBModels.Teachers.Any(m => m.Username == temp.username) || dBModels.Cleaners.Any(m => m.Username == temp.username) || dBModels.Offices.Any(m => m.Username == temp.username)) { ViewBag.Error = "User name already exist! please use another one"; List <GradeList> grades = dBModels.GradeLists.ToList(); List <subject> subjects = dBModels.subjects.ToList(); ViewBag.Grades = new SelectList(grades, "Grade", "Grade"); ViewBag.Subjects = new SelectList(subjects, "subject1", "subject1"); return(View(temp)); } else { StudentTB model = new StudentTB(); model.fullname = temp.fullname; model.gender = temp.gender; model.address = temp.address; model.email = temp.email; model.grade = temp.grade; model.parentname = temp.parentname; model.parenttpnum = temp.parenttpnum; model.password = temp.password; model.school = temp.school; model.sid = temp.sid; model.subject = temp.subject; model.tpnum = temp.tpnum; model.username = temp.username; dBModels.StudentTBs.Add(model); if (ModelState.IsValid) { dBModels.SaveChanges(); return(RedirectToAction("Index", "Student")); } else { List <GradeList> grades = dBModels.GradeLists.ToList(); List <subject> subjects = dBModels.subjects.ToList(); ViewBag.Grades = new SelectList(grades, "Grade", "Grade"); ViewBag.Subjects = new SelectList(subjects, "subject1", "subject1"); return(View(temp)); } } } //return RedirectToAction("Loginpage", "Student"); } catch { return(View()); } }