Exemplo n.º 1
0
        public ExamProperties(ScheduleRepository repo, int examToUpdateId, ExamPropertiesMode mode)
        {
            InitializeComponent();

            _repo = repo;
            _mode = mode;

            if (_mode == ExamPropertiesMode.Edit)
            {
                _exam = _repo.Exams.GetExam(examToUpdateId);
            }

            if (_mode == ExamPropertiesMode.New)
            {
                _exam = new Exam();
            }
        }
        public Exam AddExam(Exam exam)
        {
            using (var context = new ScheduleContext(ConnectionString))
            {
                exam.ExamId = 0;

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

                return exam;
            }
        }
        public void UpdateExamWOLog(Exam exam)
        {
            using (var context = new ScheduleContext(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();
            }
        }
        public void UpdateExam(Exam exam)
        {
            using (var context = new ScheduleContext(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.º 5
0
        private void Save_Click(object sender, EventArgs e)
        {
            var newExam = new Exam
            {
                ExamId = _exam.ExamId,
                DisciplineId = _exam.DisciplineId,
                IsActive = true,
                ConsultationDateTime = ConsDate.Value
            };

            var consAud = _repo.Auditoriums.Find(ConsAudBox.Text);
            if (consAud != null)
            {
                newExam.ConsultationAuditoriumId = consAud.AuditoriumId;
            }

            newExam.ExamDateTime = ExamDate.Value;
            var examAud = _repo.Auditoriums.Find(ExamAudBox.Text);
            if (examAud != null)
            {
                newExam.ExamAuditoriumId = examAud.AuditoriumId;
            }

            _repo.Exams.UpdateExam(newExam);

            Close();
        }