public ActionResult CourseEdit(int CourseId)
 {
     CourseServices services = new CourseServices();
     CourseModel model = new CourseModel();
     model = services.GetCourse(CourseId);
     return View(model);
 }
 public void CourseEdit(CourseModel model)
 {
     var editedCourse = db.Kursy.Where(x => x.IdKursu == model.CourseId).FirstOrDefault();
     if (editedCourse.Zadania == null)
     {
         editedCourse.IdKlasy = model.ClassId;
         editedCourse.IdPrzedmiotu = model.SubjectId;
         editedCourse.Opis = model.CourseDescription;
         editedCourse.Tytuł = model.CourseTitle;
     }
     else
     {
         var tasks = editedCourse.Zadania;
         foreach(var task in tasks)
         {
             if(task.Rozwiązania == null)
             {
                 editedCourse.IdKlasy = model.ClassId;
                 editedCourse.IdPrzedmiotu = model.SubjectId;
                 editedCourse.Opis = model.CourseDescription;
                 editedCourse.Tytuł = model.CourseTitle;
             }
             else
             {
                 db.Rozwiązania.RemoveRange(task.Rozwiązania);
             }
         }
     }
     db.SaveChanges();
 }
 public ActionResult CourseDelete(CourseModel model)
 {
     CourseServices services = new CourseServices();
     model.Tasks = services.GetTasks(model.CourseId);
     services.CourseDelete(model);
     return RedirectToAction("Index", "Teacher");
 }
 public ActionResult CreateCourse()
 {
     CourseModel model = new CourseModel();
     CourseServices ServiceForCourses = new CourseServices();
     UserServices ServicesForUsers = new UserServices();
     model.Subjects = ServiceForCourses.GetSubjects();
     model.Classes = ServicesForUsers.GetClasses();
     return View(model);
 }
 public ActionResult CreateCourse(CourseModel newCourse)
 {
     CourseServices CourseServ = new CourseServices();
     UserServices UserServ = new UserServices();
     HttpCookie loggedTeacher = Request.Cookies["LoggedUser"];
     TeacherModel teacher = UserServ.GetTeacher(loggedTeacher.Values.Get("Login"));
     newCourse.TeacherId = teacher.IdNauczyciela;
     CourseServ.NewCourse(newCourse);
     return RedirectToAction("Index", "Teacher");
 }
 public void CourseDelete(CourseModel model)
 {
     foreach(var item in model.Tasks)
     {
         var SolutionsToDelete = db.Rozwiązania.Where(x => x.IdZadania == item.TaskId);
         db.Rozwiązania.RemoveRange(SolutionsToDelete);
     }
     var TasksToDelete = db.Zadania.Where(x => x.IdKursu == model.CourseId).ToList();
     db.Zadania.RemoveRange(TasksToDelete);
     var CourseToDelete = db.Kursy.Where(x => x.IdKursu == model.CourseId).FirstOrDefault();
     db.Kursy.Remove(CourseToDelete);
     db.SaveChanges();
 }
 public CourseModel GetCourse(int CourseId)
 {
     var course = db.Kursy.Where(x => x.IdKursu == CourseId).FirstOrDefault();
     CourseModel model = new CourseModel();
     model.CourseId = course.IdKursu;
     model.ClassId = course.IdKlasy;
     model.Class = db.Klasy.Where(x => x.IdKlasy == course.IdKlasy).Select(p => p.Oddział).FirstOrDefault();
     model.CourseDescription = course.Opis;
     model.CourseTitle = course.Tytuł;
     model.SubjectId = course.IdPrzedmiotu;
     model.Subject = db.Przedmioty.Where(x => x.IdPrzedmiotu == course.IdPrzedmiotu).Select(p => p.NazwaPrzedmiotu).FirstOrDefault();
     model.TeacherId = course.IdProwadzącego;
     var tasks = db.Zadania.Where(x => x.IdKursu == CourseId).ToList();
     model.Tasks = new List<TaskModel>();
     foreach(var task in tasks)
     {
         model.Tasks.Add(new TaskModel
         {
             CourseId = task.IdKursu,
             CreationDate = (DateTime)task.DataWstawienia,
             DeadLineDate = (DateTime)task.DataOddania,
             Descriprion = task.Treść,
             TaskId = task.IdZadania
         });
     }
     UserServices us = new UserServices();
     model.Subjects = GetSubjects();
     model.Classes = us.GetClasses();
     return model;
 }
 public void NewCourse(CourseModel model)
 {
     db.Kursy.Add(new Kursy
     {
         IdKursu = db.Kursy.Max(x => x.IdKursu) + 1,
         IdPrzedmiotu = model.SubjectId,
         IdProwadzącego = model.TeacherId,
         IdKlasy = model.ClassId,
         Opis = model.CourseDescription,
         Tytuł = model.CourseTitle,
     });
     db.SaveChanges();
 }
 public ActionResult ManageTasks(int CourseId)
 {
     CourseServices service = new CourseServices();
     CourseModel model = new CourseModel();
     model = service.GetCourse(CourseId);
     model.Tasks = service.GetTasks(CourseId);
     return View(model.Tasks);
 }
 public ActionResult CourseEdit(CourseModel model)
 {
     CourseServices services = new CourseServices();
     services.CourseEdit(model);
     return RedirectToAction("Index", "Teacher");
 }