Esempio n. 1
0
 public void createStudent(string firstName, string lastName, string indexNo, int groupId)
 {
     using (var db = new StorageContext())
     {
         var group = db.Groups.Find(groupId);
         var student = new Student { FirstName = firstName, LastName = lastName, IndexNo = indexNo, Group = group };
         db.Students.Add(student);
         db.SaveChanges();
     }
 }
Esempio n. 2
0
 public void deleteStudent(Student st)
 {
     using (var db = new StorageContext())
     {
         var original = db.Students.Find(st.StudentId);
         if (original != null)
         {
             db.Students.Remove(original);
             db.SaveChanges();
         }
     }
 }
Esempio n. 3
0
 public void updateStudent(Student st)
 {
     using (var db = new StorageContext())
     {
         var original = db.Students.Find(st.StudentId);
         if (original != null)
         {
             original.FirstName = st.FirstName;
             original.LastName = st.LastName;
             int groupId = original.Group.GroupId;
             original.IndexNo = st.IndexNo;
             try
             {
                 db.SaveChanges();
             }
             catch (DbEntityValidationException ex)
             {
                 Console.WriteLine(ex.EntityValidationErrors.ElementAt(0).ValidationErrors.ElementAt(0).ErrorMessage);
             }
         }
     }
 }