Exemple #1
0
        //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);
            }
        }
Exemple #2
0
 public IHttpActionResult GetItemsBySubjectId(int subjectId)
 {
     try
     {
         ItemsForSubject items = ItemsBL.GetItemsBySubjectId(subjectId);
         if (items == null)
         {
             throw new Exception();
         }
         return(Ok(items));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(Ok());
     }
 }