private dynamic RouteSearch(string searchQuery, int page, string rarity, string category, string faction, string rItems, string mItems, int id) { if (searchQuery == null) { searchQuery = ""; } sql.Open(WebSettings.Settings.CreateDescription()); var parmeter = new List <Parameter>(); bool hasFilter = !string.IsNullOrEmpty(searchQuery); FilterModel filterModel = new FilterModel { Categories = ApiDataService.SelectCategories(sql), Rarities = ApiDataService.SelectRarities(sql), Factions = ApiDataService.SelectFactions(sql), }; var rarityItem = filterModel.VerifyRarity(rarity); var categoryItem = filterModel.VerifyCategory(category); var factionItem = filterModel.VerifyFaction(faction); var showRemovedItems = filterModel.VerifyRmdItems(rItems); var showMetaItems = filterModel.VerifyMetaItems(mItems); filterModel.CurrentShowRemovedItems = showRemovedItems; filterModel.CurrentShowMetaItems = showMetaItems; string sqlQuery = DataService.BuildSearchQuery(hasFilter, true, false, id > 0, rarityItem != null, categoryItem != null, factionItem != null, showRemovedItems, showMetaItems); if (hasFilter) { var p = new Parameter { Identifier = "@filter", Value = $"%{searchQuery}%" }; parmeter.Add(p); } if (rarityItem != null) { var p = new Parameter { Identifier = "@rarity", Value = $"{rarityItem.Id}" }; parmeter.Add(p); } if (categoryItem != null) { var p = new Parameter { Identifier = "@category", Value = $"{categoryItem.Id}" }; parmeter.Add(p); } if (factionItem != null) { var p = new Parameter { Identifier = "@faction", Value = $"{factionItem.Id}" }; parmeter.Add(p); } if (id > 0) { var p = new Parameter { Identifier = "@id", Value = $"{id}" }; parmeter.Add(p); } var ds = sql.SelectDataSet(sqlQuery, parmeter); var searchResult = new List <Item>(); foreach (var row in ds) { Item item = Item.Create(row); CrossoutDataService.Instance.AddData(item); searchResult.Add(item); } //var str = JsonConvert.SerializeObject(searchResult); return(Response.AsJson(searchResult)); }
private dynamic RouteSearch(string searchQuery, int page, string rarity, string category, string faction, string rItems, string mItems) { if (searchQuery == null) { searchQuery = ""; } DataService db = new DataService(sql); sql.Open(WebSettings.Settings.CreateDescription()); var parmeter = new List <Parameter>(); bool hasFilter = !string.IsNullOrEmpty(searchQuery); FilterModel filterModel = new FilterModel { Categories = SelectCategories(sql), Rarities = SelectRarities(sql), Factions = SelectFactions(sql), }; var rarityItem = filterModel.VerifyRarity(rarity); var categoryItem = filterModel.VerifyCategory(category); var factionItem = filterModel.VerifyFaction(faction); var showRemovedItems = filterModel.VerifyRmdItems(rItems); var showMetaItems = filterModel.VerifyMetaItems(mItems); filterModel.CurrentShowRemovedItems = showRemovedItems; filterModel.CurrentShowMetaItems = showMetaItems; string sqlQuery = DataService.BuildSearchQuery(hasFilter, true, false, false, rarityItem != null, categoryItem != null, factionItem != null, showRemovedItems, showMetaItems); if (hasFilter) { var p = new Parameter { Identifier = "@filter", Value = $"%{searchQuery}%" }; parmeter.Add(p); } if (rarityItem != null) { var p = new Parameter { Identifier = "@rarity", Value = $"{rarityItem.Id}" }; parmeter.Add(p); } if (categoryItem != null) { var p = new Parameter { Identifier = "@category", Value = $"{categoryItem.Id}" }; parmeter.Add(p); } if (factionItem != null) { var p = new Parameter { Identifier = "@faction", Value = $"{factionItem.Id}" }; parmeter.Add(p); } page = Math.Max(1, page); int entriesPerPage = 50; int from = entriesPerPage * (page - 1); var limita = new Parameter { Identifier = "@from", Value = from }; var limitb = new Parameter { Identifier = "@to", Value = entriesPerPage }; parmeter.Add(limita); parmeter.Add(limitb); var count = GetCount(sql, hasFilter, parmeter, rarityItem, categoryItem, factionItem, showRemovedItems, showMetaItems); int maxPages = (int)Math.Ceiling(count / (float)entriesPerPage); var ds = sql.SelectDataSet(sqlQuery, parmeter); var searchResult = new List <Item>(); foreach (var row in ds) { Item item = Item.Create(row); // CrossoutDataService.Instance.AddData(item); searchResult.Add(item); } // CurrentPage = page, MaxRows = count, MaxPages = maxPages PagerModel pager = new PagerModel { CurrentPage = page, MaxRows = count, MaxPages = maxPages }; SearchModel searchModel = new SearchModel { SearchResult = searchResult, Pager = pager, FilterModel = filterModel, CurrentQuery = searchQuery }; var statusModel = db.SelectStatus(); searchModel.Status = statusModel; return(View["search", searchModel]); }