public void HasNoQuery_Is_False_When_Category_Is_Specified_And_Name_Is_Empty() { var query = new MetaSearchQuery { Name = "", Category = "Category" }; Assert.False(query.HasNoQuery()); }
public void HasNoQuery_Is_False_When_Name_Is_Specified_And_Category_Is_Whitespace() { var query = new MetaSearchQuery { Name = "name", Category = " " }; Assert.False(query.HasNoQuery()); }
public List <MetaData> SearchForMetadata(MetaSearchQuery searchArgument) { var query = TableWithAllNestedObjects() .AsQueryable(); if (searchArgument == null || searchArgument.HasNoQuery()) { return(GetAll(BaseListQuery.DefaultValues(_languageConfig.Default))); } var searchArgsHasName = !string.IsNullOrWhiteSpace(searchArgument.Name); var searchArgsHasCategory = !string.IsNullOrWhiteSpace(searchArgument.Category); if (searchArgsHasCategory) { query = query.Where(x => x.Category.Name.ToLower().Equals(searchArgument.Category.ToLower())); } if (searchArgsHasName) { query = query.Where(x => x.Name.ToLower().Contains(searchArgument.Name.ToLower())); } var totalItems = query.Count(); var totalPages = Convert.ToInt32(Math.Ceiling(totalItems * 1.0 / searchArgument.PageSize)); if (searchArgument.Page > totalPages) { searchArgument.Page = 1; } var offset = searchArgument.PageSize * (searchArgument.Page - 1); var meta = query .OrderBy(x => x.Id) .Skip(offset) .Take(searchArgument.PageSize) .ToList(); meta.ForEach(x => { x.TotalItems = totalItems; x.NumberOfPages = totalPages; }); return(meta); }