protected void lnkSend_Click(object sender, EventArgs e) { Student s = new Student(); s.FirstName = txtFirstName.Text; s.LastName = txtLastName.Text; s.Gender = int.Parse(drpGender.SelectedValue.ToString()); String gun = txtGun.Text; String ay = drpAy.SelectedValue; String yil = txtYil.Text; DateTime BirthDate = DateTime.Parse(gun + "-" + ay + "-" + yil); s.DateOfBirth = BirthDate; int classId = int.Parse(drpClassrooms.SelectedValue); s.ClassId = classId; db.Students.Add(s); db.SaveChanges(); /* * // Select sorgusu * Student s2 = db.Students.Where(st => st.Id == 1).FirstOrDefault(); * * // Update * db.SaveChanges(); * * // Delete * db.Students.Remove(s2); * db.SaveChanges(); */ Response.Redirect("/index.aspx"); }
protected void lnkAdd_Click(object sender, EventArgs e) { OtomDBEntities db = new OtomDBEntities(); String courseName = txtCourseName.Text; Course c = new Course(); c.CourseName = courseName; db.Courses.Add(c); db.SaveChanges(); Response.Redirect("/Index.aspx"); }
protected void btnSend_Click(object sender, EventArgs e) { OtomDBEntities db = new OtomDBEntities(); String classRoomName = txtClassroomName.Text; Classroom c = new Classroom(); c.ClassName = classRoomName; db.Classrooms.Add(c); db.SaveChanges(); Response.Redirect("/index.aspx"); }
protected void lnkSave_Click(object sender, EventArgs e) { int courseId = int.Parse(drpCourses.SelectedValue.ToString()); Course c = db.Courses.Where(c1 => c1.Id == courseId).SingleOrDefault(); List <string> selectedStudents = chkStudents.Items.Cast <ListItem>().Where(i => i.Selected).Select(i => i.Value).ToList(); List <Student> students = new List <Student>(); for (int i = 0; i < selectedStudents.Count; i++) { int studentId = int.Parse(selectedStudents[i]); Student s = db.Students.Where(s1 => s1.Id == studentId).SingleOrDefault(); students.Add(s); } c.Students = students; db.SaveChanges(); Response.Redirect("/index.aspx"); }