Example #1
0
        public void AddExam(Exam exam)
        {
            using (var context = new SessionContext(ConnectionString))
            {
                exam.ExamId = 0;

                context.Exams.Add(exam);
                context.SaveChanges();
            }
        }
Example #2
0
        public void AddExamsRange(IEnumerable<Exam> examList)
        {
            using (var context = new SessionContext(ConnectionString))
            {
                foreach (var exam in examList)
                {
                    exam.ExamId = 0;
                    context.Exams.Add(exam);
                }

                context.SaveChanges();
            }
        }
Example #3
0
        public void BackupDB(string filename)
        {
            using (var context = new SessionContext(ConnectionString))
            {
                var dbName = ExtractDBName(context.Database.Connection.ConnectionString);

                if (dbName == "")
                {
                    return;
                }

                var backupSQL = "BACKUP DATABASE " + dbName + " TO DISK = '" + filename + "' WITH FORMAT, MEDIANAME='" + dbName + "'";

                ExecuteQuery(backupSQL);
            }
        }
Example #4
0
        public void UpdateExamWOLog(Exam exam)
        {
            using (var context = new SessionContext(ConnectionString))
            {
                var curExam = GetExam(exam.ExamId);

                curExam.ConsultationAuditoriumId = exam.ConsultationAuditoriumId;
                curExam.ConsultationDateTime = exam.ConsultationDateTime;
                curExam.DisciplineId = exam.DisciplineId;
                curExam.ExamAuditoriumId = exam.ExamAuditoriumId;
                curExam.ExamDateTime = exam.ExamDateTime;
                curExam.ExamId = exam.ExamId;
                curExam.IsActive = exam.IsActive;

                context.SaveChanges();
            }
        }
Example #5
0
        public void UpdateExam(Exam exam)
        {
            using (var context = new SessionContext(ConnectionString))
            {
                var oldExam = context.Exams.FirstOrDefault(e => e.ExamId == exam.ExamId);
                oldExam.IsActive = false;

                exam.ExamId = 0;

                context.Exams.Add(exam);
                context.SaveChanges();

                var logEntry = new LogEvent() { OldExam = oldExam, NewExam = exam, DateTime = DateTime.Now };

                context.EventLog.Add(logEntry);
                context.SaveChanges();
            }
        }
Example #6
0
 public void SaveChanges()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         context.SaveChanges();
     }
 }
Example #7
0
 public void CreateDB()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         if (!context.Database.Exists())
         {
             ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
         }
     }
 }
Example #8
0
        private void RemoveLogEvent(int logEventId)
        {
            using (var context = new SessionContext(ConnectionString))
            {
                var logEvent = context.EventLog.FirstOrDefault(le => le.LogEventId == logEventId);

                context.EventLog.Remove(logEvent);
                context.SaveChanges();
            }
        }
Example #9
0
 public Exam GetFirstFiltredExam(Func<Exam, bool> condition)
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context.Exams.ToList().FirstOrDefault(condition);
     }
 }
Example #10
0
 public List<Exam> GetFiltredExams(Func<Exam, bool> condition)
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context.Exams.ToList().Where(condition).ToList();
     }
 }
Example #11
0
 public Exam GetExam(int examId)
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context.Exams.FirstOrDefault(a => a.ExamId == examId);
     }
 }
Example #12
0
 public List<LogEvent> GetAllLogEvents()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context
             .EventLog
             .Include(e => e.OldExam)
             .Include(e => e.NewExam)
             .ToList();
     }
 }
Example #13
0
 public List<Exam> GetAllExams()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context
             .Exams
             .Where(e => e.IsActive)
             .ToList();
     }
 }
Example #14
0
 public List<Exam> GetAllExamRecords()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context
             .Exams
             .ToList();
     }
 }
Example #15
0
 private void Dispose(bool b)
 {
     using (var context = new SessionContext(ConnectionString))
     {
         context.Dispose();
     }
 }
Example #16
0
 private LogEvent GetLogEvent(int logEventId)
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context
             .EventLog
             .Include(e => e.OldExam)
             .Include(e => e.NewExam)
             .FirstOrDefault(le => le.LogEventId == logEventId);
     }
 }
Example #17
0
 public int GetTotalExamsCount()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context
             .Exams
             .Count(e => e.IsActive);
     }
 }
Example #18
0
 public void RecreateDB()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         context.Database.Delete();
         context.Database.CreateIfNotExists();
     }
 }
Example #19
0
        public void RemoveExam(int examId)
        {
            using (var context = new SessionContext(ConnectionString))
            {
                var exam = context.Exams.FirstOrDefault(e => e.ExamId == examId);

                context.Exams.Remove(exam);
                try
                {
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    throw;
                }
            }
        }
Example #20
0
        public void ClearAllExams()
        {
            using (var context = new SessionContext(ConnectionString))
            {
                var examIds = context.Exams.Select(e => e.ExamId).ToList();

                foreach (var examId in examIds)
                {
                    RemoveExam(examId);
                }
            }
        }
Example #21
0
        public void ClearExamLogs()
        {
            using (var context = new SessionContext(ConnectionString))
            {
                var logIds = context.EventLog.Select(le => le.LogEventId).ToList();

                foreach (var logId in logIds)
                {
                    RemoveLogEvent(logId);
                }
            }
        }