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); }
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); }
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); }
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"); } }
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."); } } }
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"); } }
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"); } }
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"); } }
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"); } }
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"); } }
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"); } }
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"); } }
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"); } } }
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"); } }
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"); } } }
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"); } } }
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"); } }
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"); } }
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); }
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"); } }
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); }
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); }
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"); } } }
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"); } }
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."); } } }
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"); } }
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"); } }
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."); } }
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."); } }
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"); } }