public ActionResult Create([Bind(Include = "Id,Name")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                db.Teachers.Add(teacher);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(teacher));
        }
Пример #2
0
        public ActionResult Create([Bind(Include = "Id,Name")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
        public ActionResult Create([Bind(Include = "Id,Name,TeacherId")] Course course)
        {
            if (ModelState.IsValid)
            {
                db.Courses.Add(course);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TeacherId = new SelectList(db.Teachers, "Id", "Name", course.TeacherId);
            return(View(course));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "Id,Name,CourseId")] Assignment assignment)
        {
            if (ModelState.IsValid)
            {
                db.Assignments.Add(assignment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CourseId = new SelectList(db.Courses, "Id", "Name", assignment.CourseId);
            return(View(assignment));
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "Id,StudentId,CourseId")] StudentCourse studentCourse)
        {
            if (ModelState.IsValid)
            {
                db.StudentCourses.Add(studentCourse);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CourseId  = new SelectList(db.Courses, "Id", "Name", studentCourse.CourseId);
            ViewBag.StudentId = new SelectList(db.Students, "Id", "Name", studentCourse.StudentId);
            return(View(studentCourse));
        }
        public ActionResult Create([Bind(Include = "Id,StudentId,AssignmentId")] StudentAssignment studentAssignment)
        {
            if (ModelState.IsValid)
            {
                db.StudentAssignments.Add(studentAssignment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AssignmentId = new SelectList(db.Assignments, "Id", "Name", studentAssignment.AssignmentId);
            ViewBag.StudentId    = new SelectList(db.Students, "Id", "Name", studentAssignment.StudentId);
            return(View(studentAssignment));
        }
Пример #7
0
 private void deleteBT_Click(object sender, EventArgs e)                                                 // This method run when deleteBT clicked
 {
     try                                                                                                 // Holding errors
     {
         using (SchoolDatabaseEntities schoolDatabase = new SchoolDatabaseEntities())                    // Create temporary object of SchoolDatabaseEntities
         {
             var entry = schoolDatabase.Entry(students);                                                 // This variable store information about current state of entry on object
             if (entry.State == EntityState.Detached)                                                    // If state is detached
             {
                 schoolDatabase.students.Attach(students);                                               // Ataching student object to table
             }
             schoolDatabase.students.Remove(students);                                                   // Removeing students object from table
             schoolDatabase.SaveChanges();                                                               // Saveing changes
             refreshDataGridView();                                                                      // Refreshing DataGridView with students
             clear();                                                                                    // Run clear method
         }
         MessageBox.Show("Removeing record successfull !", "Entity Inforamtion",                         // Inform user about successfull inserting record
                         MessageBoxButtons.OK, MessageBoxIcon.Information);                              // Set buttons and icon for messagebox
     }
     catch (Exception exception)                                                                         // If some error become
     {
         MessageBox.Show("Error, contact system admin ! \n" + exception.ToString(), "Entity Error",      // Inform user about some error
                         MessageBoxButtons.OK, MessageBoxIcon.Error);                                    // Set buttons and icon for messagebox
     }
 }
Пример #8
0
 private void saveBT_Click(object sender, EventArgs e)                                                   // This method run when saveBT clicked
 {
     try                                                                                                 // Holding errors
     {
         students.name    = nameTB.Text.Trim();                                                          // Set value of name as a nameTB.Text
         students.surname = surnameTB.Text.Trim();                                                       // Set value of surname as a surnameTB.Text
         students.age     = Convert.ToInt32(ageTB.Text.Trim());                                          // Set value of age as a ageTB.Text
         students.@class  = classTB.Text.Trim();                                                         // Set value of class as a classTB.Text
         students.address = addressTB.Text.Trim();                                                       // Set value of address as a addressTB.Text
         using (SchoolDatabaseEntities schoolDatabase = new SchoolDatabaseEntities())                    // Create temporary object of SchoolDatabaseEntities
         {
             schoolDatabase.Entry(students).State = EntityState.Modified;                                // Modify the current record
             schoolDatabase.SaveChanges();                                                               // Saving changes
         }
         clear();                                                                                        // Run clear method
         refreshDataGridView();                                                                          // Refreshing DataGridView with students
         MessageBox.Show("Updateing record successfull !", "Entity Inforamtion",                         // Inform user about successfull inserting record
                         MessageBoxButtons.OK, MessageBoxIcon.Information);                              // Set buttons and icon for messagebox
     }
     catch (Exception exception)                                                                         // If some error become
     {
         MessageBox.Show("Error, contact system admin ! \n" + exception.ToString(), "Entity Error",      // Inform user about some error
                         MessageBoxButtons.OK, MessageBoxIcon.Error);                                    // Set buttons and icon for messagebox
     }
 }