Exemplo n.º 1
0
        public DataTablesResponse GetListAuthor(IDataTablesRequest dataTableParam, ResourceAuthorSearchViewModel searchViewModel)
        {
            try
            {
                var query = ResourceRepository.GetAll(x => x.IsDeleted == false && x.Type == (int)ResourceType.Author, null, x => x.Authors);
                if (searchViewModel.AuthorId > 0)
                {
                    query = query.Where(x => x.Authors.Any(g => g.IsDeleted == false && g.Id == searchViewModel.AuthorId));
                }

                var dataTableHelper = new DataTableHelper<ResourceAuthorViewModel, Resource>(query, x => new ResourceAuthorViewModel
                {
                    Id = x.Id,
                    Url = x.Url,
                    Tag = x.Tag,
                    Author = x.Authors.AsQueryable().Any(y => y.IsDeleted == false) ? x.Authors.AsQueryable().FirstOrDefault().Name : ""
                });

                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<ResourceAuthorViewModel>(), 0, 0);
            }
        }
Exemplo n.º 2
0
 public ActionResult GetListAuthor(IDataTablesRequest dataTableParam, ResourceAuthorSearchViewModel searchViewModel)
 {
     return Json(ResourceBusiness.GetListAuthor(dataTableParam, searchViewModel));
 }