public List <SqlParameter> GetGoodsParameters(GoodsSelector goodsSelector) { List <SqlParameter> sqlParameters = new List <SqlParameter>(); if (goodsSelector.Producers != null) { sqlParameters.Add(CreateProducerParameter(goodsSelector.Producers)); } if (goodsSelector.Countries != null) { sqlParameters.Add(CreateCountryParameter(goodsSelector.Countries)); } if (goodsSelector.Materials != null) { sqlParameters.Add(CreateMaterialParameter(goodsSelector.Materials)); } if (goodsSelector.Colors != null) { sqlParameters.Add(CreateColorParameter(goodsSelector.Colors)); } if (goodsSelector.PriceFrom != null) { sqlParameters.Add(CreatePriceFromParameter(goodsSelector.PriceFrom)); } if (goodsSelector.PriceTo != null) { sqlParameters.Add(CreatePriceToParameter(goodsSelector.PriceTo)); } sqlParameters.AddRange(CreateFromToParameters(goodsSelector.Page, goodsSelector.ShowGoods)); sqlParameters.Add(CreateOrderTypeParameter(goodsSelector.OrderType)); sqlParameters.Add(CreateSortDirParameter(goodsSelector.SortDir)); sqlParameters.Add(CreateCountParameter()); return(sqlParameters); }
public async Task <List <GoodCellModel> > SearchGoodCells(GoodsSelector goodsSelector) { var parameters = _parametersCreator.GetGoodsParameters(goodsSelector).ToArray(); var goodsDbInformation = await _context.GetGoodsDbInformation("GetGoods", parameters); return(goodsDbInformation.GoodCells); }
public async Task <GoodsInformation <string> > SearchGoodsInformation(GoodsSelector goodsSelector) { var parameters = _parametersCreator.GetGoodsParameters(goodsSelector).ToArray(); var goodsDbInformation = await _context.GetGoodsDbInformation("GetGoods", parameters); var questions = _questionsGrouper.GroupGoods(goodsSelector, goodsDbInformation.DBQuestions); return(new GoodsInformation <string>(_parametersCreator.GetCount(parameters), goodsDbInformation.GoodCells, questions)); }
public GoodsInformationSearcherFactory(IGoodsInformationSearcher goodsInformationSearcher, IGoodCellsSearcher goodCellsSearcher, ICacheKeyCreator keyCreator, GoodsSelector goodsSelector) { _goodsInformationSearcher = goodsInformationSearcher; _goodCellsSearcher = goodCellsSearcher; _keyCreator = keyCreator; _goodsSelector = goodsSelector; }
public List <QuestionsBase <string> > GroupGoods(GoodsSelector goodsSelector, List <DBQuestionBase> dBQuestions) { return(new List <QuestionsBase <string> >() { _questionsCreator.GroupProducers(dBQuestions), _questionsCreator.GroupCountries(dBQuestions), _questionsCreator.GroupMaterials(dBQuestions), _questionsCreator.GroupColors(dBQuestions), _questionsCreator.GroupPrices(dBQuestions, goodsSelector.PriceFrom, goodsSelector.PriceTo) }); }
public CacheGoodsInformationType GetCacheGoodsInformationType(GoodsSelector goodsSelector) { var type = goodsSelector.GetType(); var properties = type.GetProperties(); bool haveGoodsQuestions = false; foreach (var prop in properties) { var defaultValue = prop.PropertyType.IsValueType ? Activator.CreateInstance(prop.PropertyType) : null; var value = prop.GetValue(goodsSelector); if (haveGoodsQuestions) { var cacheGoodsInformationType = CheckNormalProperty(value, defaultValue, prop.Name); if (cacheGoodsInformationType == CacheGoodsInformationType.No) { return(CacheGoodsInformationType.No); } } else { var cacheGoodsInformationType = CheckProperty(value, defaultValue, prop.Name); switch (cacheGoodsInformationType) { case CacheGoodsInformationType.GoodsQuestions: haveGoodsQuestions = true; break; case CacheGoodsInformationType.No: return(CacheGoodsInformationType.No); } } } if (haveGoodsQuestions) { return(CacheGoodsInformationType.GoodsQuestions); } return(CacheGoodsInformationType.GoodsInformation); }
public async Task <GoodsInformation <string> > CreateGoodsInformation(GoodsSelector goodsSelector, IGoodsInformationSearcherFactory goodsInformationSearcherFactory) { var cacheGoodsInformation = await _cache.GetGoodsInformation(goodsInformationSearcherFactory.GetKey(), goodsSelector); if (cacheGoodsInformation == null) { cacheGoodsInformation = new CacheGoodsInformation <string>(); } if (cacheGoodsInformation.Type == CacheGoodsInformationType.No || cacheGoodsInformation.Type == CacheGoodsInformationType.AddNew) { cacheGoodsInformation.GoodsInformation = await goodsInformationSearcherFactory.SearchGoodsInformation(); if (cacheGoodsInformation.Type == CacheGoodsInformationType.AddNew) { await _cache.AddGoodsInformation(goodsInformationSearcherFactory.GetKey(), cacheGoodsInformation.GoodsInformation); } } else if (cacheGoodsInformation.Type == CacheGoodsInformationType.GoodsQuestions) { cacheGoodsInformation.GoodsInformation.GoodCells = await goodsInformationSearcherFactory.SearchGoodCells(); } return(cacheGoodsInformation.GoodsInformation); }
public async Task <GoodsInformation <string> > GetGoodsInformation([FromBody] GoodsSelector goodsSelector) { return(await _goodsInformationCreator.CreateGoodsInformation(goodsSelector, new GoodsInformationSearcherFactory(_goodsInformationSearcher, _goodCellsSearcher, _keyCreator, goodsSelector))); }
public async Task <CacheGoodsInformation <string> > GetGoodsInformation(string key, GoodsSelector selector) { var cacheGoodsInformationType = _cacheGoodsInformationTypeCreator.GetCacheGoodsInformationType(selector); var cacheGoodsInformation = new CacheGoodsInformation <string>() { Type = cacheGoodsInformationType }; switch (cacheGoodsInformationType) { case CacheGoodsInformationType.GoodsInformation: case CacheGoodsInformationType.GoodsQuestions: var goodsInformationFactory = new GoodsInformationFactory(); var json = await _client.GetGoodsInformationAsync(new Key() { Key_ = key }); if (json.Equals(new GrpcCacheGoodsInformation())) { return(new CacheGoodsInformation <string>() { Type = CacheGoodsInformationType.AddNew }); } var goodsInformation = goodsInformationFactory.CreateGoodsInformation(json); cacheGoodsInformation.GoodsInformation = goodsInformation; break; } return(cacheGoodsInformation); }