Пример #1
0
        public DataTablesResponse GetListChapter(IDataTablesRequest dataTableParam, ResourceChapterSearchViewModel searchViewModel)
        {
            try
            {
                var query = ResourceRepository.GetAll(x => x.IsDeleted == false && x.Type == (int)ResourceType.Chapter);
                if (searchViewModel.AuthorId > 0)
                {
                    query = query.Where(x => x.Authors.Any(g => g.IsDeleted == false && g.Id == searchViewModel.AuthorId));
                }
                if (searchViewModel.GenreId > 0)
                {
                    query = query.Where(x => x.Genres.Any(g => g.IsDeleted == false && g.Id == searchViewModel.GenreId));
                }
                if (searchViewModel.CategoryId > 0)
                {
                    query = query.Where(x => x.ChapterResources.Any(g => g.IsDeleted == false && g.Chapter.CategoryId == searchViewModel.CategoryId));
                }
                if (searchViewModel.ChapterId > 0)
                {
                    query = query.Where(x => x.ChapterResources.Any(g => g.IsDeleted == false && g.ChapterId == searchViewModel.ChapterId));
                }

                var dataTableHelper = new DataTableHelper<ResourceChapterViewModel, Resource>(query, x => new ResourceChapterViewModel
                {
                    Id = x.Id,
                    Url = x.Url,
                    Tag = x.Tag,
                    Order = x.Order,
                    Chapter = x.ChapterResources.AsQueryable().Any(y => y.IsDeleted == false) ? x.ChapterResources.AsQueryable().FirstOrDefault().Chapter.Title : ""
                });

                var entities = dataTableHelper.GetDataVMForResponse(dataTableParam);
                var result = dataTableHelper.GetDataToList(dataTableParam, entities);

                return new DataTablesResponse(dataTableParam.Draw, result, entities.Count(), entities.Count());
            }
            catch (Exception ex)
            {
                Provider.Instance.LogError(ex);
                return new DataTablesResponse(dataTableParam.Draw, new List<ResourceChapterViewModel>(), 0, 0);
            }
        }
Пример #2
0
 public ActionResult GetListChapter(IDataTablesRequest dataTableParam, ResourceChapterSearchViewModel searchViewModel)
 {
     return Json(ResourceBusiness.GetListChapter(dataTableParam, searchViewModel));
 }