예제 #1
0
        public void DeleteDiscipline(int disciplineId)
        {
            var lectures = _db.Lectures.Where(t => t.DisciplineId == disciplineId).Select(t => t.Id).ToList();

            foreach (var lecture in lectures)
            {
                var modules = _db.Modules.Where(t => t.LectureId == lecture).Select(t => t.Id).ToList();
                foreach (var module in modules)
                {
                    var questions = _db.Questions.Where(t => t.ModuleId == module).Select(t => t.Id).ToList();
                    foreach (var que in questions)
                    {
                        _db.Answers.RemoveRange(_db.Answers.Where(t => t.QuestionId == que));
                    }
                    _db.Questions.RemoveRange(_db.Questions.Where(t => t.ModuleId == module));
                }
                _db.Modules.RemoveRange(_db.Modules.Where(t => t.LectureId == lecture));
            }
            _db.LectorDisciplines.RemoveRange(_db.LectorDisciplines.Where(t => t.DisciplineId == disciplineId));
            _db.StudentDisciplines.RemoveRange(_db.StudentDisciplines.Where(t => t.DisciplineId == disciplineId));
            _db.Lectures.RemoveRange(_db.Lectures.Where(t => t.DisciplineId == disciplineId));
            var disc = new Discipline()
            {
                Id = disciplineId
            };

            _db.Entry(disc).State = EntityState.Deleted;
            _db.SaveChanges();
        }
예제 #2
0
        public void EditDiscipline(int disciplineId, string name, int?lectorId)
        {
            var disc = _db.Disciplines.FirstOrDefault(t => t.Id == disciplineId);

            if (lectorId != null)
            {
                if (_db.LectorDisciplines.Any(t => t.DisciplineId == disciplineId))
                {
                    var connect = _db.LectorDisciplines.FirstOrDefault(t => t.DisciplineId == disciplineId);
                    if (connect != null)
                    {
                        connect.LectorId = Convert.ToInt32(lectorId);
                    }
                    _db.SaveChanges();
                }
                else
                {
                    var lecturesTable = _db.Set <LectorDiscipline>();
                    lecturesTable.Add(new LectorDiscipline()
                    {
                        LectorId = Convert.ToInt32(lectorId), DisciplineId = disciplineId
                    });
                }
            }
            if (disc != null)
            {
                disc.Name = name;
            }
            _db.SaveChanges();
        }
예제 #3
0
        public void AddNewDiscipline(string name, int?lectorId)
        {
            var disciplinesTable = _db.Set <Discipline>();

            disciplinesTable.Add(new Discipline()
            {
                Name = name
            });
            _db.SaveChanges();
            var disciplineId  = _db.Disciplines.FirstOrDefault(t => t.Name == name).Id;
            var lecturesTable = _db.Set <LectorDiscipline>();

            lecturesTable.Add(new LectorDiscipline()
            {
                LectorId = Convert.ToInt32(lectorId), DisciplineId = disciplineId
            });
            _db.SaveChanges();
        }