public async Task <IActionResult> Delete(string Id) { var spec = await(from d in DBContext.Specialities where d.Id.ToString() == Id select d).FirstOrDefaultAsync(); if (spec != null) { var dep = await(from i in DBContext.Departments.Include(d => d.Specialities) where i.Specialities.Contains(spec) select i).FirstOrDefaultAsync(); DBContext.Remove(spec); await DBContext.SaveChangesAsync(); DisciplineFilesChecker checker = new DisciplineFilesChecker(); checker.Check(environment, DBContext); return(RedirectToAction("Index", new { DepId = dep.Id })); } return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> DeleteFile(string FileId) { var file = await(from f in DBContext.Files where f.Id.ToString() == FileId select f).FirstOrDefaultAsync(); var disc = await(from di in DBContext.Disciplines.Include(f => f.Files) where di.Files.Contains(file) select di).FirstOrDefaultAsync(); if (Directory.Exists(file.Path.Replace("/", @"\"))) { ; } { System.IO.File.Delete(file.Path); } DBContext.Update(disc).Entity.Files.Remove(file); DBContext.Remove(file); await DBContext.SaveChangesAsync(); return(RedirectToAction("Index", new { DiscId = disc.Id })); }
public async Task <IActionResult> EditSchedule(EditScheduleViewModel model) { var spec = await(from sp in DBContext.Specialities.Include(s => s.Schedules) where sp.Id.ToString() == model.SpecialityId select sp).FirstOrDefaultAsync(); var oldShedule = await(from sc in DBContext.WeekSchedules where sc.id == model.WeekScheduleId select sc).FirstOrDefaultAsync(); spec.Schedules.Remove(oldShedule); DBContext.Remove(oldShedule); if (model.WeekScheduleName == null) { model.WeekScheduleName = "Без названия"; } var NewWeekSchedule = new EWeekSchedule() { Name = model.WeekScheduleName, Speciality = spec, Schedule = new List <EDaySchedule>(6) }; // DBContext.WeekSchedules.Add(NewWeekSchedule); NewWeekSchedule.Schedule.Add(new EDaySchedule()//mon { WeekSchedule = NewWeekSchedule, DayNumber = 0, DisciplinesForDay = new List <EScheduleItem>(8) }); //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]); for (int i = 0; i < 8; i++) { var discipline = model.mon[i]; discipline.DaySchedule = NewWeekSchedule.Schedule[0]; if (discipline.DisciplineId.ToString() == "-1") { discipline.Name = "Нет пары"; discipline.TeacherFIO = ""; discipline.Type = ""; } else { var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher) where di.Id == discipline.DisciplineId select di).FirstOrDefaultAsync(); discipline.Name = disc.Name; discipline.TeacherFIO = disc.Teacher.FIO; } if (discipline.Classroom == null) { discipline.Classroom = ""; } NewWeekSchedule.Schedule[0].DisciplinesForDay.Add(discipline); } NewWeekSchedule.Schedule.Add(new EDaySchedule()//tue { WeekSchedule = NewWeekSchedule, DayNumber = 1, DisciplinesForDay = new List <EScheduleItem>(8) }); //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]); for (int i = 0; i < 8; i++) { var discipline = model.tue[i]; discipline.DaySchedule = NewWeekSchedule.Schedule[1]; if (discipline.DisciplineId.ToString() == "-1") { discipline.Name = "Нет пары"; discipline.TeacherFIO = ""; discipline.Type = ""; } else { var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher) where di.Id == discipline.DisciplineId select di).FirstOrDefaultAsync(); discipline.Name = disc.Name; discipline.TeacherFIO = disc.Teacher.FIO; } if (discipline.Classroom == null) { discipline.Classroom = ""; } NewWeekSchedule.Schedule[1].DisciplinesForDay.Add(discipline); } NewWeekSchedule.Schedule.Add(new EDaySchedule()//wed { WeekSchedule = NewWeekSchedule, DayNumber = 2, DisciplinesForDay = new List <EScheduleItem>(8) }); //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]); for (int i = 0; i < 8; i++) { var discipline = model.wed[i]; discipline.DaySchedule = NewWeekSchedule.Schedule[2]; if (discipline.DisciplineId.ToString() == "-1") { discipline.Name = "Нет пары"; discipline.TeacherFIO = ""; discipline.Type = ""; } else { var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher) where di.Id == discipline.DisciplineId select di).FirstOrDefaultAsync(); discipline.Name = disc.Name; discipline.TeacherFIO = disc.Teacher.FIO; } if (discipline.Classroom == null) { discipline.Classroom = ""; } NewWeekSchedule.Schedule[2].DisciplinesForDay.Add(discipline); } NewWeekSchedule.Schedule.Add(new EDaySchedule()//thu { WeekSchedule = NewWeekSchedule, DayNumber = 3, DisciplinesForDay = new List <EScheduleItem>(8) }); //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]); for (int i = 0; i < 8; i++) { var discipline = model.thu[i]; discipline.DaySchedule = NewWeekSchedule.Schedule[3]; if (discipline.DisciplineId.ToString() == "-1") { discipline.Name = "Нет пары"; discipline.TeacherFIO = ""; discipline.Type = ""; } else { var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher) where di.Id == discipline.DisciplineId select di).FirstOrDefaultAsync(); discipline.Name = disc.Name; discipline.TeacherFIO = disc.Teacher.FIO; } if (discipline.Classroom == null) { discipline.Classroom = ""; } NewWeekSchedule.Schedule[3].DisciplinesForDay.Add(discipline); } NewWeekSchedule.Schedule.Add(new EDaySchedule()//fri { WeekSchedule = NewWeekSchedule, DayNumber = 4, DisciplinesForDay = new List <EScheduleItem>(8) }); //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]); for (int i = 0; i < 8; i++) { var discipline = model.fri[i]; discipline.DaySchedule = NewWeekSchedule.Schedule[4]; if (discipline.DisciplineId.ToString() == "-1") { discipline.Name = "Нет пары"; discipline.TeacherFIO = ""; discipline.Type = ""; } else { var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher) where di.Id == discipline.DisciplineId select di).FirstOrDefaultAsync(); discipline.Name = disc.Name; discipline.TeacherFIO = disc.Teacher.FIO; } if (discipline.Classroom == null) { discipline.Classroom = ""; } NewWeekSchedule.Schedule[4].DisciplinesForDay.Add(discipline); } NewWeekSchedule.Schedule.Add(new EDaySchedule()//sat { WeekSchedule = NewWeekSchedule, DayNumber = 5, DisciplinesForDay = new List <EScheduleItem>(8) }); //DBContext.DaySchedules.Add(NewWeekSchedule.Schedule[0]); for (int i = 0; i < 8; i++) { var discipline = model.sat[i]; discipline.DaySchedule = NewWeekSchedule.Schedule[5]; if (discipline.DisciplineId.ToString() == "-1") { discipline.Name = "Нет пары"; discipline.TeacherFIO = ""; discipline.Type = ""; } else { var disc = await(from di in DBContext.Disciplines.Include(t => t.Teacher) where di.Id == discipline.DisciplineId select di).FirstOrDefaultAsync(); discipline.Name = disc.Name; discipline.TeacherFIO = disc.Teacher.FIO; } if (discipline.Classroom == null) { discipline.Classroom = ""; } NewWeekSchedule.Schedule[5].DisciplinesForDay.Add(discipline); } spec.Schedules.Add(NewWeekSchedule); DBContext.Add(NewWeekSchedule); await DBContext.SaveChangesAsync(); return(RedirectToAction("Index", new { SpecId = spec.Id })); }