public Supplier(ISqlExecutor executor, IMapper mapper, SupplierPoco supplierPoco, SupplierViewObject viewObject) { _supplierValue = supplierPoco; _supplierViewObject = viewObject; _sqlExecutor = executor; _supplierMapper = mapper; }
public async Task <bool> LoadAuxValue(SupplierPoco supplier) { var queryStoreFactory = new QueryStoreFactory(); var queryStore = queryStoreFactory.GetQueryStore(); /// queryStore.AddParam(QueryType.QuerySupplierType, supplier.TIPO.ToString()); /// queryStore.AddParam(QueryType.AccountById, supplier.CUGASTO); return(true); }
private void FillCities(ref SupplierPoco poco) { var city = from c in _cityDtos where c.Code == _supplierValue.CP select c; var singleCity = city.FirstOrDefault(); if (singleCity != null) { poco.POBLACION = singleCity.Poblacion; } }
/* TODO: Refactor this like the client loader. Too many queries. It is slow. * Too many resposabiltities for this function * in the crud there is a */ public async Task <bool> LoadValue(IDictionary <string, string> fields, string code) { var currentQuery = string.Format(SupplierQuery, code); Valid = false; MonthsDtos = fillMonths(); using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection()) { try { var queryResult = await connection.QueryAsync <SupplierPoco>(currentQuery).ConfigureAwait(false); _supplierValue = queryResult.FirstOrDefault(c => c.NUM_PROVEE == code); if (_supplierValue == null) { return(false); } Value = _supplierMapper.Map <SupplierPoco, SupplierViewObject>(_supplierValue); // now we look for aux tables. if (_supplierValue.TIPO.HasValue) { var supplierType = await connection.GetAsyncAll <TIPOPROVE>(); Type = _supplierMapper.Map <IEnumerable <TIPOPROVE>, IEnumerable <SupplierTypeViewObject> >(supplierType); } IEnumerable <CU1> accounts = await connection.QueryAsync <CU1>(AccountSelect); AccountDtos = _supplierMapper.Map <IEnumerable <CU1>, IEnumerable <AccountViewObject> >(accounts); var provincia = await connection.QueryAsync <PROVINCIA>(ProvinciaSelectAll); // await BuildAndExecute<PROVINCIA>(connection, ProvinciaSelect, _supplierValue.PROV); if (provincia != null) { ProvinceDtos = _supplierMapper.Map <IEnumerable <PROVINCIA>, IEnumerable <ProvinceViewObject> >(provincia); } var pais = await connection.QueryAsync <Country>(PaisSelectAll); if (pais != null) { CountryDtos = _supplierMapper.Map <IEnumerable <Country>, IEnumerable <CountryViewObject> >(pais); } var banks = await BuildAndExecute <BANCO>(connection, BankSelect, _supplierValue.BANCO); if (banks != null) { BanksDtos = _supplierMapper.Map <IEnumerable <BANCO>, IEnumerable <BanksViewObject> >(banks); if (_supplierValue.VIA.HasValue) { var vias = await BuildAndExecute <VIAS, byte>(connection, ViaSelect, _supplierValue.VIA.Value); ViasDtos = _supplierMapper.Map <IEnumerable <VIAS>, IEnumerable <ViaViewObject> >(vias); } } QueryStoreFactory queryStoreFactory = new QueryStoreFactory(); IQueryStore store = queryStoreFactory.GetQueryStore(); store.AddParam(QueryType.QuerySuppliersBranches); var qs = store.BuildQuery(); var branches = await BuildAndExecute <ProDelegaPoco>(connection, qs, _supplierValue.NUM_PROVEE); var tmp = _supplierMapper.Map <IEnumerable <ProDelegaPoco>, IEnumerable <BranchesViewObject> >(branches); BranchesDto = tmp; var contacts = await BuildAndExecute <ProContactos>(connection, GenericSql.ContactsQuery, _supplierValue.NUM_PROVEE); ContactsDto = _supplierMapper.Map <IEnumerable <ProContactos>, IEnumerable <ContactsViewObject> >(contacts); //var months = await connection.QueryAsync<MESES>(MonthsSelect); //MonthsDtos = _supplierMapper.Map<IEnumerable<MESES>, IEnumerable<MonthsViewObject>>(months); var languages = await connection.QueryAsync <IDIOMAS>(LanguageSelect); LanguageDtos = _supplierMapper.Map <IEnumerable <IDIOMAS>, IEnumerable <LanguageViewObject> >(languages); var paymentForms = await connection.QueryAsync <FORMAS>(PaymentFormSelect); PaymentDtos = _supplierMapper.Map <IEnumerable <FORMAS>, IEnumerable <PaymentFormViewObject> >(paymentForms); var currency = await connection.QueryAsync <DIVISAS>(CurrencySelect); CurrencyDtos = _supplierMapper.Map <IEnumerable <DIVISAS>, IEnumerable <CurrencyViewObject> >(currency); // poblacion mapping var globalMapper = MapperField.GetMapper(); if (_supplierValue.FORMA_ENVIO.HasValue) { var deliveringForm = await BuildAndExecute <FORMAS_PEDENT>(connection, GenericSql.DeliveringFromQuery, _supplierValue?.FORMA_ENVIO.ToString()); var mapper = MapperField.GetMapper(); DeliveringFormDto = globalMapper.Map <IEnumerable <FORMAS_PEDENT>, IEnumerable <DeliveringFormViewObject> >(deliveringForm); } var cityMapper = _supplierMapper; var cityQuery = string.Format(_queryCity); var cities = await connection.QueryAsync <POBLACIONES>(cityQuery); var mappedCityDtos = cityMapper.Map <IEnumerable <POBLACIONES>, IEnumerable <CityViewObject> >(cities); CityDtos = new ObservableCollection <CityViewObject>(mappedCityDtos); // office mapping string query = string.Format(OfficeSelect, _supplierValue.OFICINA); var office = await connection.QueryAsync <OFICINAS>(query); var mappedOffices = _supplierMapper.Map <IEnumerable <OFICINAS>, IEnumerable <OfficeViewObject> >(office); OfficeDtos = new ObservableCollection <OfficeViewObject>(mappedOffices); query = string.Format(CompanySelect, _supplierValue.SUBLICEN); var company = await connection.QueryAsync <SUBLICEN>(query); CompanyDtos = _supplierMapper.Map <IEnumerable <SUBLICEN>, IEnumerable <CompanyViewObject> >(company); Value = _supplierMapper.Map <SupplierPoco, SupplierViewObject>(_supplierValue); Valid = true; } catch (System.Exception e) { throw new DataLayerException("Cannot load supplier " + e.Message, e); } } return(Valid); }