public List <NewsResponseDto> GetNews(NewsConditionSearch conditionSearch) { try { if (conditionSearch == null) { conditionSearch = new NewsConditionSearch(); } var paging = new Commons.Paging(db.News.Count(x => !x.DelFlag && (conditionSearch.KeySearch == null || (conditionSearch.KeySearch != null && (x.Title.Contains(conditionSearch.KeySearch))))) , conditionSearch.CurrentPage, conditionSearch.PageSize); var listOfNews = db.News.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 NewsResponseDto { Id = x.Id, Title = x.Title, ImageUrl = x.ImageUrl, Summary = x.Summary, Content = x.Content, CreatedAt = x.CreatedAt }).ToList(); return(listOfNews == null ? null : listOfNews); } catch (Exception e) { throw e; } }
public List <TeacherResponseDto> GetListOfTeachers(TeacherConditionSearch 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 TeacherConditionSearch(); } // Lấy các thông tin dùng để phân trang var paging = new Commons.Paging(db.Teachers.Count(x => !x.DelFlag && (conditionSearch.KeySearch == null || (conditionSearch.KeySearch != null && ((x.User.FirstName.Contains(conditionSearch.KeySearch)) || (x.User.LastName.Contains(conditionSearch.KeySearch)))))) , conditionSearch.CurrentPage, conditionSearch.PageSize); // Tìm kiếm và lấy dữ liệu theo trang var listTeacherFromDb = db.Teachers.Include(u => u.User).Include(y => y.Team).Where(x => !x.DelFlag && (conditionSearch.KeySearch == null || (conditionSearch.KeySearch != null && ((x.User.FirstName.Contains(conditionSearch.KeySearch)) || (x.User.LastName.Contains(conditionSearch.KeySearch)))))) .OrderBy(x => x.Id) .Skip((paging.CurrentPage - 1) * paging.NumberOfRecord) .Take(paging.NumberOfRecord).ToList(); if (listTeacherFromDb == null) { return(null); } var listOfTeacher = listTeacherFromDb.Select(t => new TeacherResponseDto { Id = t.Id, TeamInfo = new TeamResponseDto(t.Team), UserInfo = new UserResponseDto(t.User) }).ToList(); return(listOfTeacher); } catch (Exception e) { throw 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; } }