Exemplo n.º 1
0
 public List<Student> getStudents()
 {
     using (var db = new StorageContext())
     {
         return db.Students.ToList();
     }
 }
Exemplo n.º 2
0
 public List<Student> getGroupStudents(Group selectedGroup)
 {
     using (var db = new StorageContext())
     {
         return db.Students.Where(student => student.Group.GroupId.Equals(selectedGroup.GroupId)).ToList();
     }
 }
Exemplo n.º 3
0
 public List<Group> getGroups()
 {
     using (var db = new StorageContext())
     {
         return db.Groups.ToList();
     }
 }
Exemplo n.º 4
0
        public void createStudent(string firstName, string lastName/*, string indexNo*/, int groupId)
        {
            try
            {
                using (var db = new StorageContext())
                {
                    var group = db.Groups.Find(groupId);
                    var student = new Student
                    {
                        FirstName = firstName,
                        LastName = lastName,
                        Group = group
                    };

                    db.Students.Add(student);
                    db.SaveChanges();
                    student.IndexNo = Convert.ToString(student.StudentId);
                    db.SaveChanges();

                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var errors in dbEx.EntityValidationErrors)
                {
                    foreach (var error in errors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property name: {0} Error: {1}", error.PropertyName, error.ErrorMessage);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void deleteStudent(Student student)
        {
            try
            {
                using (var db = new StorageContext())
                {
                    var oldStudent = db.Students.Find(student.StudentId);
                    if (oldStudent != null)
                    {
                        db.Students.Remove(oldStudent);
                        db.SaveChanges();
                    }

                }
            }
            catch (Exception e)
            {
                Console.Write(e.ToString());
            }
        }
Exemplo n.º 6
0
 public void updateStudent(Student newStudent)
 {
     using (var db = new StorageContext())
     {
         var oldStudent = db.Students.Find(newStudent.StudentId);
         if (oldStudent != null)
         {
             oldStudent.FirstName = newStudent.FirstName;
             oldStudent.LastName = newStudent.LastName;
             try
             {
                 db.SaveChanges();
             }
             catch (DbEntityValidationException dbEx)
             {
                 foreach (var errors in dbEx.EntityValidationErrors)
                 {
                     foreach (var error in errors.ValidationErrors)
                     {
                         Trace.TraceInformation("Property name: {0} Error: {1}", error.PropertyName, error.ErrorMessage);
                     }
                 }
             }
         }
     }
 }