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

                context.Exams.Add(exam);
                context.SaveChanges();
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 6
0
 public void SaveChanges()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
 public void CreateDB()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         if (!context.Database.Exists())
         {
             ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
         }
     }
 }
Exemplo n.º 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();
            }
        }
Exemplo n.º 9
0
 public Exam GetFirstFiltredExam(Func<Exam, bool> condition)
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context.Exams.ToList().FirstOrDefault(condition);
     }
 }
Exemplo n.º 10
0
 public List<Exam> GetFiltredExams(Func<Exam, bool> condition)
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context.Exams.ToList().Where(condition).ToList();
     }
 }
Exemplo n.º 11
0
 public Exam GetExam(int examId)
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context.Exams.FirstOrDefault(a => a.ExamId == examId);
     }
 }
Exemplo n.º 12
0
 public List<LogEvent> GetAllLogEvents()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context
             .EventLog
             .Include(e => e.OldExam)
             .Include(e => e.NewExam)
             .ToList();
     }
 }
Exemplo n.º 13
0
 public List<Exam> GetAllExams()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context
             .Exams
             .Where(e => e.IsActive)
             .ToList();
     }
 }
Exemplo n.º 14
0
 public List<Exam> GetAllExamRecords()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context
             .Exams
             .ToList();
     }
 }
Exemplo n.º 15
0
 private void Dispose(bool b)
 {
     using (var context = new SessionContext(ConnectionString))
     {
         context.Dispose();
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 17
0
 public int GetTotalExamsCount()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         return context
             .Exams
             .Count(e => e.IsActive);
     }
 }
Exemplo n.º 18
0
 public void RecreateDB()
 {
     using (var context = new SessionContext(ConnectionString))
     {
         context.Database.Delete();
         context.Database.CreateIfNotExists();
     }
 }
Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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);
                }
            }
        }