Пример #1
0
 public bool Exists(TutoringSession ts)
 {
     using (var context = new LabManagerDbContext())
     {
         return(context.TutoringSession.Any(x => x.Equals(ts)));
     }
 }
Пример #2
0
 public bool Exists(Course c)
 {
     using (var context = new LabManagerDbContext())
     {
         return(context.Course.Any(x => x.Equals(c)));
     }
 }
Пример #3
0
 public void AddTutoringSession(TutoringSession ts)
 {
     using (var context = new LabManagerDbContext())
     {
         context.TutoringSession.Add(ts);
         context.SaveChanges();
     }
 }
Пример #4
0
 public Course GetCourse(String code)
 {
     using (var context = new LabManagerDbContext())
     {
         Course dbCourse = context.Course.Find(code);
         return(dbCourse);
     }
 }
Пример #5
0
 public void AddTutor(Tutor t)
 {
     using (var context = new LabManagerDbContext())
     {
         context.Tutor.Add(t);
         context.SaveChanges();
     }
 }
Пример #6
0
 public void AddCourse(Course c)
 {
     using (var context = new LabManagerDbContext())
     {
         context.Course.Add(c);
         context.SaveChanges();
     }
 }
Пример #7
0
        public Decimal GetPlannedHours(String ssn)
        {
            using (var context = new LabManagerDbContext())
            {
                SqlParameter parameter = new SqlParameter("@ssn", ssn);

                return(context.Database.SqlQuery <Decimal>("SELECT dbo.Tutor_GetPlannedHours (@ssn)", parameter).FirstOrDefault());
            }
        }
Пример #8
0
        public void UpdateTutoringSession(TutoringSessionUpdateDTO dtoUpdate)
        {
            TutoringSession old     = dtoUpdate.Old;
            TutoringSession updated = dtoUpdate.Updated;

            using (var context = new LabManagerDbContext())
            {
                TutoringSession dbTs = context.TutoringSession
                                       .Include(x => x.Tutors)
                                       .SingleOrDefault(x => x.Code.Equals(old.Code) && x.StartTime.Equals(old.StartTime) && x.EndTime.Equals(old.EndTime));
                if (dbTs == null)
                {
                    return;
                }

                List <TutorTutoringSession> addedSessions   = updated.Tutors.Except(dbTs.Tutors).ToList();
                List <TutorTutoringSession> deletedSessions = dbTs.Tutors.Except(updated.Tutors).ToList();

                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        // Deleted entries
                        deletedSessions.ForEach(c => dbTs.Tutors.Remove(c));

                        if (!old.Equals(updated))
                        {
                            // Keys have been changed
                            context.TutoringSession.Remove(dbTs);
                            context.TutoringSession.Add(updated);
                        }
                        else if (!old.FullEquals(updated))
                        {
                            dbTs.NumberOfParticipants = updated.NumberOfParticipants;
                            foreach (TutorTutoringSession ptt in addedSessions)
                            {
                                object[] parameters = new object[4];
                                parameters[0] = new SqlParameter("@ssn", ptt.Ssn);
                                parameters[1] = new SqlParameter("@code", ptt.Code);
                                parameters[2] = new SqlParameter("@startTime", ptt.StartTime);
                                parameters[3] = new SqlParameter("@endTime", ptt.EndTime);

                                context.Database.ExecuteSqlCommand("EXEC dbo.TutorTutoringSession_Add @ssn, @code, @startTime, @endTime", parameters);
                            }
                        }
                        context.SaveChanges();

                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
        }
Пример #9
0
 public TutoringSession GetTutoringSession(String code, DateTime startTime, DateTime endTime)
 {
     using (var context = new LabManagerDbContext())
     {
         TutoringSession dbTs = context.TutoringSession
                                .Include(x => x.Tutors)
                                .SingleOrDefault(x => x.Code.Equals(code) && x.StartTime.Equals(startTime) && x.EndTime.Equals(endTime));
         return(dbTs);
     }
 }
Пример #10
0
 public Tutor GetTutor(String ssn)
 {
     using (var context = new LabManagerDbContext())
     {
         Tutor dbTutor = context.Tutor
                         .Include(x => x.TutoringSessions.Select(ts => ts.Tutor))
                         .Include(x => x.TutoringSessions.Select(ts => ts.TutoringSession))
                         .SingleOrDefault(x => x.Ssn.Equals(ssn));
         return(dbTutor);
     }
 }
Пример #11
0
 public List <Tutor> GetAllTutors()
 {
     using (var context = new LabManagerDbContext())
     {
         List <Tutor> dbTutors = context.Tutor
                                 .Include(x => x.TutoringSessions.Select(ts => ts.Tutor))
                                 .Include(t => t.TutoringSessions.Select(ts => ts.TutoringSession.Course))
                                 .ToList();
         return(dbTutors);
     }
 }
Пример #12
0
 public List <Course> GetAllCourses()
 {
     using (var context = new LabManagerDbContext())
     {
         List <Course> dbCourses = context.Course
                                   .Include(x => x.TutoringSessions.Select(ts => ts.Tutors))
                                   .Include(x => x.TutoringSessions.Select(ts => ts.Course))
                                   .ToList();
         return(dbCourses);
     }
 }
Пример #13
0
        public int GetNumberOfTutors(String code, DateTime startTime, DateTime endTime)
        {
            using (var context = new LabManagerDbContext())
            {
                object[] parameters = new object[3];
                parameters[0] = new SqlParameter("@code", code);
                parameters[1] = new SqlParameter("@startTime", startTime);
                parameters[2] = new SqlParameter("@endTime", endTime);

                return(context.Database.SqlQuery <int>("SELECT dbo.TutorTutoringSession_GetNumberOfTutors (@code, @startTime, @endTime)", parameters).FirstOrDefault());
            }
        }
Пример #14
0
 public List <TutoringSession> GetAllTutoringSessions()
 {
     using (var context = new LabManagerDbContext())
     {
         List <TutoringSession> dbTs = context.TutoringSession
                                       .Include(ts => ts.Tutors.Select(tts => tts.Tutor))
                                       .Include(ts => ts.Tutors.Select(tts => tts.TutoringSession))
                                       .Include(ts => ts.Course)
                                       .ToList();
         return(dbTs);
     }
 }
Пример #15
0
        public Decimal GetStudentsPerTutorRatio(String code, DateTime startTime, DateTime endTime)
        {
            using (var context = new LabManagerDbContext())
            {
                object[] parameters = new object[3];
                parameters[0] = new SqlParameter("@code", code);
                parameters[1] = new SqlParameter("@startTime", startTime);
                parameters[2] = new SqlParameter("@endTime", endTime);

                return(context.Database.SqlQuery <Decimal>("SELECT dbo.TutoringSession_GetStudentsPerTutorRatio (@code, @startTime, @endTime)", parameters).FirstOrDefault());
            }
        }
Пример #16
0
 public void DeleteTutor(Tutor t)
 {
     using (var context = new LabManagerDbContext())
     {
         Tutor dbTutor = context.Tutor.Find(t.Ssn);
         if (dbTutor == null)
         {
             return;
         }
         context.Tutor.Remove(dbTutor);
         context.SaveChanges();
     }
 }
Пример #17
0
 public void DeleteCourse(Course c)
 {
     using (var context = new LabManagerDbContext())
     {
         Course dbCourse = context.Course.Find(c.Code);
         if (dbCourse == null)
         {
             return;
         }
         context.Course.Remove(dbCourse);
         context.SaveChanges();
     }
 }
Пример #18
0
 public void DeleteTutoringSession(TutoringSession ts)
 {
     using (var context = new LabManagerDbContext())
     {
         TutoringSession dbTutoringSession = context.TutoringSession
                                             .Find(ts.Code, ts.StartTime, ts.EndTime);
         if (dbTutoringSession == null)
         {
             return;
         }
         context.TutoringSession.Remove(dbTutoringSession);
         context.SaveChanges();
     }
 }
Пример #19
0
 public void UpdateCourse(Course c)
 {
     using (var context = new LabManagerDbContext())
     {
         Course dbC = context.Course
                      .Include(x => x.TutoringSessions.Select(ts => ts.Tutors))
                      .Include(x => x.TutoringSessions.Select(ts => ts.Course))
                      .SingleOrDefault(x => x.Code.Equals(c.Code));
         if (dbC == null)
         {
             return;
         }
         context.Entry(dbC).CurrentValues.SetValues(c);
         context.SaveChanges();
     }
 }