public ActionResult DeleteCourse(string courseId) { try { Course c = service.GetObject(Int64.Parse(courseId)); ICourseChangeRepository courseChangeRepository = ObjectFactory.GetInstance <ICourseChangeRepository>(); ICourseClassRepository courseClassRepository = ObjectFactory.GetInstance <ICourseClassRepository>(); ICourseTimeRepository courseTimeRepository = ObjectFactory.GetInstance <ICourseTimeRepository>(); IAttachmentCourseRepository attachmentCourseRepository = ObjectFactory.GetInstance <IAttachmentCourseRepository>(); ISelectableCourseStudentRepository selectableCourseStudentRepository = ObjectFactory.GetInstance <ISelectableCourseStudentRepository>(); foreach (var x in attachmentCourseRepository.GetObjectList(x => x.CourseId == c.Id, x => x.CourseId, Core.Enums.OrderingType.Ascending, 0, 0)) { attachmentCourseRepository.Delete(x); } foreach (var x in courseClassRepository.GetObjectList(x => x.Courses_Id == c.Id, x => x.Courses_Id, Core.Enums.OrderingType.Ascending, 0, 0)) { courseClassRepository.Delete(x); } foreach (var x in courseChangeRepository.GetObjectList(x => x.CourseId == c.Id, x => x.CourseId, Core.Enums.OrderingType.Ascending, 0, 0)) { courseChangeRepository.Delete(x); } foreach (var x in courseTimeRepository.GetObjectList(x => x.CourseId == c.Id, x => x.CourseId, Core.Enums.OrderingType.Ascending, 0, 0)) { courseTimeRepository.Delete(x); } foreach (var x in selectableCourseStudentRepository.GetObjectList(x => x.SelectedCourses_Id == c.Id, x => x.SelectedCourses_Id, Core.Enums.OrderingType.Ascending, 0, 0)) { selectableCourseStudentRepository.Delete(x); } service.DeleteObject(c); return(Content("success")); } catch (Exception e) { return(Content(e.Message)); } }
public ActionResult DeleteAttachment() { try { var aid = Int64.Parse(Request.QueryString["aid"]); var cid = Int64.Parse(Request.QueryString["cid"]); IAttachmentCourseRepository attachmentCourseRepository = ObjectFactory.GetInstance <IAttachmentCourseRepository>(); IAttachmentService attachmentService = ObjectFactory.GetInstance <IAttachmentService>(); attachmentCourseRepository.Delete(attachmentCourseRepository.GetFirstOrDefaultObject(x => x.AttachmentId == aid && x.CourseId == cid)); return(Content("success")); } catch (Exception e) { return(Content(e.Message)); } }