public List <SlideResponseDto> GetSlide(SlideConditionSearch conditionSearch) { // Nếu không tồn tại điều kiện tìm kiếm thì khởi tạo giá trị tìm kiếm ban đầu if (conditionSearch == null) { conditionSearch = new SlideConditionSearch(); } // Lấy các thông tin dùng để phân trang var paging = new Paging(db.Slides.Count(x => !x.DelFlag && (conditionSearch.KeySearch == null || (conditionSearch.KeySearch != null && (x.Title.Contains(conditionSearch.KeySearch))))) , conditionSearch.CurrentPage, conditionSearch.PageSize); // Tìm kiếm và lấy dữ liệu theo trang var listOfSlide = db.Slides.Where(x => !x.DelFlag && (conditionSearch.KeySearch == null || (conditionSearch.KeySearch != null && (x.Title.Contains(conditionSearch.KeySearch))))) .OrderBy(x => x.Id) .Skip((paging.CurrentPage - 1) * paging.PageSize) .Take(paging.PageSize).Select(x => new SlideResponseDto { Id = x.Id, Title = x.Title, ImageUrl = x.ImageUrl, IsShowing = x.IsShowing, Content = x.Content, Url = x.Url, CreatedAt = x.CreatedAt }).ToList(); return(listOfSlide ?? listOfSlide); }
public IHttpActionResult GetSlides([FromBody] SlideConditionSearch conditionSearch) { try { return(Ok(_slideService.GetSlide(conditionSearch))); } catch (System.Exception e) { return(InternalServerError(e)); } }
public List <SlideResponseDto> GetSlides(SlideConditionSearch conditionSearch) { try { // Nếu không tồn tại điều kiện tìm kiếm thì khởi tạo giá trị tìm kiếm ban đầu if (conditionSearch == null) { conditionSearch = new SlideConditionSearch(); } // Lấy các thông tin dùng để phân trang var paging = new Commons.Paging(db.Slides.Count(x => !x.DelFlag && (conditionSearch.KeySearch == null || (conditionSearch.KeySearch != null && (x.Title.Contains(conditionSearch.KeySearch))))) , conditionSearch.CurrentPage, conditionSearch.PageSize); // Tìm kiếm và lấy dữ liệu theo trang var listOfSlide = db.Slides.Where(x => !x.DelFlag && (conditionSearch.KeySearch == null || (conditionSearch.KeySearch != null && (x.Title.Contains(conditionSearch.KeySearch))))) .OrderBy(x => x.Id) .Skip((paging.CurrentPage - 1) * paging.NumberOfRecord) .Take(paging.NumberOfRecord).Select(x => new SlideResponseDto { Id = x.Id, Title = x.Title, ImageUrl = x.ImageUrl, Path = x.Path, IsShown = x.IsShown }).ToList(); return(listOfSlide == null ? null:listOfSlide); } catch (Exception e) { throw e; } }