//Delete public static void DeleteSubject(Subjects1 subject) { Subjects newSubject = SubjectsConvertor.ConvertToDL(subject); ItemsSubjectBL.DeleteItemsSubjectBySubjectId(newSubject.SubjectId); SubjectsDL.DeleteSubject(newSubject); }
//GetItemsBySubjectId public static ItemsForSubject GetItemsBySubjectId(int subjectId) { try { List <Items> lst = new List <Items>(ItemsDL.GetAllItems().Where(i => i.ItemsSubject.FirstOrDefault(s => s.SubjectId == subjectId) != null)); ItemsForSubject itemsForSubject = new ItemsForSubject(); var subjectName = SubjectsDL.GeSubjectById(subjectId).Subject; var folderpath = $"{HttpContext.Current.Server.MapPath("~/Files/")}{EnumItemsKinds.Bookmarks}"; if (Directory.Exists(folderpath) && File.Exists($"{folderpath}/{subjectName}")) { itemsForSubject.bookmarksPath = $"{folderpath}/{subjectName}"; } folderpath = $"{HttpContext.Current.Server.MapPath("~/Files/")}{EnumItemsKinds.Book}"; if (Directory.Exists(folderpath) && File.Exists($"{ folderpath}/{subjectName}")) { itemsForSubject.bookPath = $"{folderpath}/{subjectName}"; } folderpath = $"{HttpContext.Current.Server.MapPath("~/Files/")}Image"; if (Directory.Exists(folderpath) && File.Exists($"{ folderpath}/{subjectName}")) { itemsForSubject.bookPath = $"{folderpath}/{subjectName}"; } folderpath = $"{HttpContext.Current.Server.MapPath("~/Files/")}{EnumItemsKinds.Lesson}"; if (Directory.Exists(folderpath) && File.Exists($"{ folderpath}/{subjectName}")) { itemsForSubject.bookPath = $"{folderpath}/{subjectName}"; } folderpath = $"{HttpContext.Current.Server.MapPath("~/Files/")}{EnumItemsKinds.Video}"; if (Directory.Exists(folderpath) && File.Exists($"{ folderpath}/{subjectName}")) { itemsForSubject.bookPath = $"{folderpath}/{subjectName}"; } folderpath = $"{HttpContext.Current.Server.MapPath("~/Files/")}{EnumItemsKinds.LessonSummary}"; if (Directory.Exists(folderpath) && File.Exists($"{ folderpath}/{subjectName}")) { itemsForSubject.lessonSummary = FilesDL.GetTextFromFile($"{folderpath}/{subjectName}"); } return(itemsForSubject); } catch (Exception ex) { return(null); } }
//GetItemsForAllSubjects public static List <ItemsForSubject> GetItemsForAllSubjects() { List <Subjects> subjects = SubjectsDL.GetAllSubjects(); List <ItemsForSubject> itemsForSubjects = new List <ItemsForSubject>(); foreach (var subject in subjects) { var result = GetItemsBySubjectId(subject.SubjectId); if (result != null) { itemsForSubjects.Add(result); } } return(itemsForSubjects); }
//GetAll public static List <Subjects1> GetAllSubjects() { return(SubjectsConvertor.ConvertToListDto(SubjectsDL.GetAllSubjects())); }
//GetContainName public static List <Subjects1> GetSubjectContainText(string text) { List <Subjects> lst = new List <Subjects>(SubjectsDL.GetAllSubjects()); return(SubjectsConvertor.ConvertToListDto(lst.Where(k => k.Subject.Contains(text)).ToList())); }
//GetByName public static Subjects1 GetSubjectByName(string subject) { List <Subjects> lst = new List <Subjects>(SubjectsDL.GetAllSubjects()); return(SubjectsConvertor.ConvertToDto(lst.Where(k => k.Subject.Equals(subject)).FirstOrDefault())); }
//GetById public static Subjects1 GetSubjectById(int subjectId) { return(SubjectsConvertor.ConvertToDto(SubjectsDL.GeSubjectById(subjectId))); }
//Update public static void UpdateSubject(Subjects1 s) { SubjectsDL.UpdateSubject(SubjectsConvertor.ConvertToDL(s)); }
//Add public static void AddSubject(Subjects1 subject) { Subjects newSubject = SubjectsConvertor.ConvertToDL(subject); SubjectsDL.AddSubject(newSubject); }