public ServiceResponse <List <Lesson> > GetLessons(LessonFilterModel filter) { var response = new ServiceResponse <List <Lesson> >(); response.IsSucceeded = true; response.RecordsTotal = lessonRepository.ListQueryable.Count(); response.RecordsFiltered = lessonRepository.ListQueryable.AddSearchFilters(filter).Count(); response.Result = lessonRepository.ListQueryable.AddSearchFilters(filter).AddOrderAndPageFilters(filter).ToList(); return(response); }
public IActionResult GetLessons(LessonFilterModel model) { try { var result = _LessonService.GetLessons(model); if (result.IsSucceeded) { return(Ok(result.Result)); } return(BadRequest(result.ErrorMessage)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public static IQueryable <Lesson> AddSearchFilters(this IQueryable <Lesson> input, LessonFilterModel filter) { if (filter != null) { if (filter.Term?.Length > 0) { input = input.Where(x => x.LessonName.Contains(filter.Term)); } if (filter.NameTerm?.Length > 0) { input = input.Where(x => x.LessonName.ToLower().Contains(filter.NameTerm.ToLower())); } if (filter.Active != null) { input = input.Where(x => x.IsActive == filter.Active); } if (filter.Deleted != null) { input = input.Where(x => x.IsDelete == filter.Deleted); } } return(input); }