Ejemplo n.º 1
0
 public List<Student> getStudents(int groupId)
 {
     using (var db = new StorageContext())
         return db.Students.Where(
             student => student.Group.GroupId == groupId)
                           .ToList();
 }
Ejemplo n.º 2
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();
     }
 }
Ejemplo n.º 3
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();
         }
     }
 }
Ejemplo n.º 4
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);
             }
         }
     }
 }
Ejemplo n.º 5
0
 public List<Group> getGroups()
 {
     using (var db = new StorageContext())
         return db.Groups.ToList();
 }