public ActionResult DeleteConfirmed(int id) { var file = new FilesController(); Module module = db.Modules.AsNoTracking().FirstOrDefault(a => a.Id == id); //Find(id); var activities = module.Activities.ToList(); foreach (var a in activities) { var files = a.Files.ToList(); file.DeleteFiles(files); } var moduleFiles = module.Files.ToList(); file.DeleteFiles(moduleFiles); //ViewBag.CourseId = module.CourseId; try { module = db.Modules.Find(id); db.Modules.Remove(module); db.SaveChanges(); TempData["Event"] = "Module " + module.Name + " removed."; } catch (Exception e) { TempData["NegativeEvent"] = e.Message; } return(RedirectToAction("Index", new { courseId = module.CourseId })); }
public ActionResult DeleteConfirmed(string email) { ApplicationDbContext newDbContext = new ApplicationDbContext(); //hitta user genom eposten ApplicationUser user = newDbContext.Users.FirstOrDefault(u => u.Email == email); if (user != null) { string presentedName = user.FullName; if (selectedList == "PartialList" || selectedList == "StudentList") { var file = new FilesController(); var files = user.Files.ToList(); bool result = file.DeleteFiles(files); if (!result) { TempData["NegativeEvent"] = "User couldn´t be removed. Error when trying to remove files for student"; if (selectedList == "StudentList") { return(RedirectToAction("StudentList")); } else { return(RedirectToAction("Details", "Courses", new { id = details })); } } } if (selectedList == "Teacherlist" && user.Files.Count > 0) { TempData["NegativeEvent"] = "User couldn´t be removed. Has uploaded course files."; return(RedirectToAction("TeacherList")); } newDbContext.Users.Remove(user); newDbContext.SaveChanges(); //in med konfirmeringsmeddelande nedan TempData["Event"] = presentedName + " removed from the LMS."; if (selectedList == "PartialList") { //här skall redirect till coursescontroller med korrekt indata av en int till till return(RedirectToAction("Details", "Courses", new { id = details })); } if (selectedList == "Teacherlist") { return(RedirectToAction("TeacherList")); } else { return(RedirectToAction("StudentList")); } } //om vi har kommit hit är originaluser inte hittad. skicka felmeddelande till klient TempData["NegativeEvent"] = "User not found. Please try again or navigate using the navbar on top of the page."; return(View()); }
public ActionResult DeleteConfirmed(int id) { FilesController file = new FilesController(); Activity activity = db.Activities.AsNoTracking().FirstOrDefault(a => a.Id == id); var files = activity.Files.ToList(); var moduleId = activity.ModuleId; bool result = file.DeleteFiles(files); if (result) { activity = db.Activities.Find(id); db.Activities.Remove(activity); db.SaveChanges(); TempData["Event"] = "Activity " + activity.Name + " removed."; } else { TempData["NegativeEvent"] = "Activity " + activity.Name + " couldn´t be removed."; } return(RedirectToAction("Details", "Modules", new { id = moduleId })); }
public ActionResult DeleteConfirmed(int id) { bool result = true; var file = new FilesController(); Course course = db.Courses.AsNoTracking().FirstOrDefault(a => a.Id == id); //Find(id); var modules = course.Modules.ToList(); foreach (var m in modules) { var activities = m.Activities.ToList(); foreach (var a in activities) { var activityFiles = a.Files.ToList(); result = file.DeleteFiles(activityFiles); } if (result) { var moduleFiles = m.Files.ToList(); result = file.DeleteFiles(moduleFiles); if (!result) { TempData["NegativeEvent"] = "Course " + course.Name + " not removed."; return(RedirectToAction("Index")); } } else { TempData["NegativeEvent"] = "Course " + course.Name + " not removed."; return(RedirectToAction("Index")); } } if (result) { var courseFiles = course.Files.ToList(); result = file.DeleteFiles(courseFiles); if (!result) { TempData["NegativeEvent"] = "Course " + course.Name + " not removed."; return(RedirectToAction("Index")); } } bool sucess = DeleteStudents(id); if (sucess) { course = db.Courses.Find(id); //Course course = db.Courses.Include(m => m.C(id); try { db.Courses.Remove(course); db.SaveChanges(); TempData["Event"] = "Course " + course.Name + " removed."; } catch (Exception e) { TempData["NegativeEvent"] = e.Message; } } return(RedirectToAction("Index")); }