示例#1
0
        private Activity GetActivityAttached(ContextDB context, int id)
        {
            Activity activityAttached = new Activity();

            activityAttached = context.Activities.Where(b => b.Id == id).Include(b => b.ActivityPayments).FirstOrDefault();
            return(activityAttached);
        }
示例#2
0
        private List <Subject> GetSubjectListAttached(ContextDB context, Teacher modifiedTeacher)
        {
            List <Subject> listOfSubjects = new List <Subject>();

            foreach (Subject actualSubject in modifiedTeacher.Subjects)
            {
                listOfSubjects.Add(context.Subjects.Where(b => b.Code == actualSubject.Code).Include(b => b.Students).FirstOrDefault());
            }
            return(listOfSubjects);
        }
示例#3
0
        private List <ActivityPayment> GetActivityPaymentsListAttached(ContextDB context, Activity modifiedActivity)
        {
            List <ActivityPayment> listOfActivityPayments = new List <ActivityPayment>();

            foreach (ActivityPayment actualActivityPayment in modifiedActivity.ActivityPayments)
            {
                listOfActivityPayments.Add(context.ActivityPayments.Where(b => b.Id == actualActivityPayment.Id).FirstOrDefault());
            }
            return(listOfActivityPayments);
        }
示例#4
0
 public SchoolVan Get(int id)
 {
     try
     {
         using (var context = new ContextDB())
         {
             SchoolVan schoolVanToFind = context.SchoolVans.Find(id);
             return(schoolVanToFind);
         }
     }
     catch (Exception)
     {
         throw new SchoolVanPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#5
0
 private void AddSchoolVan(SchoolVan schoolVan)
 {
     using (var context = new ContextDB())
     {
         try
         {
             context.SchoolVans.Add(schoolVan);
             context.SaveChanges();
         }
         catch (Exception)
         {
             throw new SchoolVanPersistanceException("Camioneta ya ingresada en el sistema.");
         }
     }
 }
示例#6
0
 public void ModifySubject(Subject modifiedSubject)
 {
     try
     {
         using (var context = new ContextDB())
         {
             context.Subjects.Attach(modifiedSubject);
             context.Entry(modifiedSubject).State = EntityState.Modified;
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw new SubjectPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#7
0
 public Teacher Get(int id)
 {
     try
     {
         using (var context = new ContextDB())
         {
             Teacher teacherToFind = context.Teachers.Find(id);
             context.Teachers.Include(d => d.Subjects).ToList();
             return(teacherToFind);
         }
     }
     catch (Exception)
     {
         throw new StudentPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#8
0
 public void RemoveTeacher(Teacher teacher)
 {
     try
     {
         using (var context = new ContextDB())
         {
             context.Teachers.Attach(teacher);
             context.Teachers.Remove(teacher);
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw new StudentPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#9
0
 private void RemoveActivity(Activity activity)
 {
     try
     {
         using (var context = new ContextDB())
         {
             context.Activities.Attach(activity);
             context.Activities.Remove(activity);
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw new ActivityPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#10
0
 public Activity Get(int id)
 {
     try
     {
         using (var context = new ContextDB())
         {
             Activity activityToFind = context.Activities.Find(id);
             context.Activities.Include(d => d.ActivityPayments).ToList();
             return(activityToFind);
         }
     }
     catch (Exception)
     {
         throw new ActivityPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#11
0
 public Subscription Get(int id)
 {
     try
     {
         using (var context = new ContextDB())
         {
             Subscription subscriptionToFind = context.Subscriptions.Find(id);
             context.Subscriptions.Include(d => d.Student).ToList();
             return(subscriptionToFind);
         }
     }
     catch (Exception)
     {
         throw new SubscriptionPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#12
0
 private void RemoveSubscription(Subscription subscription)
 {
     try
     {
         using (var context = new ContextDB())
         {
             context.Subscriptions.Attach(subscription);
             context.Subscriptions.Remove(subscription);
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw new SubscriptionPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#13
0
 private void AddSubscription(Subscription subscription)
 {
     using (var context = new ContextDB())
     {
         try
         {
             context.Students.Attach(subscription.Student);
             context.Subscriptions.Add(subscription);
             context.SaveChanges();
         }
         catch (Exception e)
         {
             throw new SubscriptionPersistanceException("Se ha perdido la conexion con el servidor");
         }
     }
 }
示例#14
0
 private void RemoveStudent(Student student)
 {
     try
     {
         using (var context = new ContextDB())
         {
             context.Students.Attach(student);
             context.Students.Remove(student);
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw new StudentPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#15
0
 private void AddStudent(Student student)
 {
     using (var context = new ContextDB())
     {
         try
         {
             student.Subjects = GetSubjectListAttached(context, student);
             context.Students.Add(student);
             context.SaveChanges();
         }
         catch (Exception e)
         {
             throw new StudentPersistanceException("Se ha perdido la conexion con el servidor");
         }
     }
 }
示例#16
0
 private void AddActivity(Activity activity)
 {
     using (var context = new ContextDB())
     {
         try
         {
             activity.ActivityPayments = GetActivityPaymentsListAttached(context, activity);
             context.Activities.Add(activity);
             context.SaveChanges();
         }
         catch (Exception e)
         {
             throw new ActivityPersistanceException("Se ha perdido la conexion con el servidor");
         }
     }
 }
示例#17
0
 public void RemoveSchoolVan(SchoolVan aSchoolVan)
 {
     try
     {
         using (var context = new ContextDB())
         {
             context.SchoolVans.Attach(aSchoolVan);
             context.SchoolVans.Remove(aSchoolVan);
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw new SchoolVanPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#18
0
 public void RemoveSubject(Subject subject)
 {
     try
     {
         using (var context = new ContextDB())
         {
             context.Subjects.Attach(subject);
             context.Subjects.Remove(subject);
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw new SubjectPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#19
0
        public List <SchoolVan> GetAllLazyLoading()
        {
            List <SchoolVan> allSchoolVans = new List <SchoolVan>();

            try
            {
                using (var context = new ContextDB())
                {
                    allSchoolVans = context.SchoolVans.ToList();
                }
            }
            catch (Exception)
            {
                throw new SchoolVanPersistanceException("Se ha perdido la conexion con el servidor");
            }
            return(allSchoolVans);
        }
示例#20
0
 public Subject Get(string id)
 {
     try
     {
         using (var context = new ContextDB())
         {
             Subject subjectToFind = context.Subjects.Find(id);
             context.Subjects.Include(d => d.Students).ToList();
             context.Subjects.Include(d => d.Teachers).ToList();
             return(subjectToFind);
         }
     }
     catch (Exception)
     {
         throw new SubjectPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#21
0
        public List <Teacher> GetAllLazyLoading()
        {
            List <Teacher> allTeachers = new List <Teacher>();

            try
            {
                using (var context = new ContextDB())
                {
                    allTeachers = context.Teachers.ToList();
                }
            }
            catch (Exception)
            {
                throw new StudentPersistanceException("Se ha perdido la conexion con el servidor");
            }
            return(allTeachers);
        }
示例#22
0
        public List <ActivityPayment> GetAllLazyLoading()
        {
            List <ActivityPayment> allActivityPayments = new List <ActivityPayment>();

            try
            {
                using (var context = new ContextDB())
                {
                    allActivityPayments = context.ActivityPayments.ToList();
                }
            }
            catch (Exception)
            {
                throw new ActivityPaymentPersistanceException("Se ha perdido la conexion con el servidor");
            }
            return(allActivityPayments);
        }
示例#23
0
 private void AddActivityPayment(ActivityPayment activityPayment)
 {
     using (var context = new ContextDB())
     {
         try
         {
             context.Students.Attach(activityPayment.Student);
             activityPayment.Activity = GetActivityAttached(context, activityPayment.Activity.Id);
             context.ActivityPayments.Add(activityPayment);
             context.SaveChanges();
         }
         catch (Exception e)
         {
             throw new ActivityPaymentPersistanceException("Se ha perdido la conexion con el servidor");
         }
     }
 }
示例#24
0
 private void ModifySchoolVan(SchoolVan modifiedSchoolVan)
 {
     try
     {
         using (var context = new ContextDB())
         {
             SchoolVan oldSchoolVan = Get(modifiedSchoolVan.Id);
             context.SchoolVans.Attach(oldSchoolVan);
             oldSchoolVan.Capacity             = modifiedSchoolVan.Capacity;
             context.Entry(oldSchoolVan).State = EntityState.Modified;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw new SchoolVanPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#25
0
        public void AddTeacher(Teacher teacher)
        {
            using (var context = new ContextDB())
            {
                try
                {
                    teacher.Subjects = GetSubjectListAttached(context, teacher);
                    context.Teachers.Add(teacher);
                    context.SaveChanges();
                }


                catch (Exception)
                {
                    throw new StudentPersistanceException("Docente ya ingresado en el sistema.");
                }
            }
        }
示例#26
0
 public void Empty()
 {
     try
     {
         using (var context = new ContextDB())
         {
             List <ActivityPayment> activityPayments = context.ActivityPayments.ToList();
             foreach (ActivityPayment actual in activityPayments)
             {
                 ActivityPayment toDelete = context.ActivityPayments.Find(actual.Id);
                 context.ActivityPayments.Remove(toDelete);
             }
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw new ActivityPaymentPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#27
0
 public void Empty()
 {
     try
     {
         using (var context = new ContextDB())
         {
             List <Subscription> students = context.Subscriptions.ToList();
             foreach (Subscription actual in students)
             {
                 Subscription toDelete = context.Subscriptions.Find(actual.Id);
                 context.Subscriptions.Remove(toDelete);
             }
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw new SubscriptionPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }
示例#28
0
 public void Empty()
 {
     try
     {
         using (var context = new ContextDB())
         {
             List <Teacher> teachers = context.Teachers.ToList();
             foreach (Teacher actual in teachers)
             {
                 Teacher toDelete = context.Teachers.Find(actual.Id);
                 context.Teachers.Remove(toDelete);
             }
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw new StudentPersistanceException("Error en la base de datos. Imposible vaciar valores de Docente.");
     }
 }
示例#29
0
 public void Empty()
 {
     try
     {
         using (var context = new ContextDB())
         {
             List <SchoolVan> schoolVans = context.SchoolVans.ToList();
             foreach (SchoolVan actual in schoolVans)
             {
                 SchoolVan toDelete = context.SchoolVans.Find(actual.Id);
                 context.SchoolVans.Remove(toDelete);
             }
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw new SchoolVanPersistanceException("Error en la base de datos. Imposible vaciar valores de camionetas.");
     }
 }
示例#30
0
 private void ModifyActivity(Activity modifiedActivity)
 {
     try
     {
         using (var context = new ContextDB())
         {
             Activity oldActivity = Get(modifiedActivity.Id);
             context.Activities.Attach(oldActivity);
             oldActivity.Name = modifiedActivity.Name;
             oldActivity.Cost = modifiedActivity.Cost;
             oldActivity.Date = modifiedActivity.Date;
             context.Entry(oldActivity).State = EntityState.Modified;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw new ActivityPersistanceException("Se ha perdido la conexion con el servidor");
     }
 }