Beispiel #1
0
 public Supplier(ISqlExecutor executor, IMapper mapper, SupplierPoco supplierPoco, SupplierDto dto)
 {
     _supplierValue  = supplierPoco;
     _supplierDto    = dto;
     _sqlExecutor    = executor;
     _supplierMapper = mapper;
 }
Beispiel #2
0
 public Supplier(ISqlExecutor executor, string id)
 {
     _sqlExecutor              = executor;
     _supplierValue            = new SupplierPoco();
     _supplierDto              = new SupplierDto();
     _supplierValue.NUM_PROVEE = id;
     _supplierDto.NUM_PROVEE   = id;
     InitializeMapping();
 }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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;
            }
        }
Beispiel #5
0
        public async Task <bool> LoadValue(IDictionary <string, string> fields, string code)
        {
            var currentQuery = string.Format(SupplierQuery, code);

            Valid = false;
            using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection())
            {
                try
                {
                    var queryResult = await connection.QueryAsync <SupplierPoco>(currentQuery);

                    _supplierValue = queryResult.FirstOrDefault(c => c.NUM_PROVEE == code);
                    if (_supplierValue == null)
                    {
                        return(false);
                    }
                    Value = _supplierMapper.Map <SupplierPoco, SupplierDto>(_supplierValue);

                    // now we look for aux tables.
                    if (_supplierValue.TIPO.HasValue)
                    {
                        short value = _supplierValue.TIPO.Value;
                        Type =
                            await BuildAndExecute <SupplierTypeDataObject, short>(connection, TipoProveSelect,
                                                                                  value);
                    }
                    IEnumerable <CU1> accounts = await connection.QueryAsync <CU1>(AccountSelect);

                    AccountDtos = _supplierMapper.Map <IEnumerable <CU1>, IEnumerable <AccountDto> >(accounts);
                    var provincia = await connection.QueryAsync <PROVINCIA>(ProvinciaSelectAll);

                    //   await BuildAndExecute<PROVINCIA>(connection, ProvinciaSelect, _supplierValue.PROV);
                    if (provincia != null)
                    {
                        ProvinciaDtos =
                            _supplierMapper.Map <IEnumerable <PROVINCIA>, IEnumerable <ProvinciaDto> >(provincia);
                    }
                    var pais = await connection.QueryAsync <Country>(PaisSelectAll);

                    if (pais != null)
                    {
                        CountryDtos = _supplierMapper.Map <IEnumerable <Country>, IEnumerable <CountryDto> >(pais);
                    }
                    var banks = await BuildAndExecute <BANCO>(connection, BankSelect, _supplierValue.BANCO);

                    if (banks != null)
                    {
                        BanksDtos = _supplierMapper.Map <IEnumerable <BANCO>, IEnumerable <BanksDto> >(banks);
                        if (_supplierValue.VIA.HasValue)
                        {
                            var vias = await BuildAndExecute <VIAS, byte>(connection, ViaSelect,
                                                                          _supplierValue.VIA.Value);

                            ViasDtos = _supplierMapper.Map <IEnumerable <VIAS>, IEnumerable <ViaDto> >(vias);
                        }
                    }


                    var branches = await BuildAndExecute <ProDelega>(connection, GenericSql.DelegationQuery,
                                                                     _supplierValue.NUM_PROVEE);

                    var tmp = _supplierMapper.Map <IEnumerable <ProDelega>, IEnumerable <BranchesDto> >(branches);
                    AdjustBranchWithProvince(ref tmp, ProvinciaDtos);
                    BranchesDtos = tmp;
                    var contacts =
                        await BuildAndExecute <ProContactos>(connection, GenericSql.ContactsQuery,
                                                             _supplierValue.NUM_PROVEE);

                    ContactsDtos = _supplierMapper.Map <IEnumerable <ProContactos>, IEnumerable <ContactsDto> >(contacts);
                    var months = await connection.QueryAsync <MESES>(MonthsSelect);

                    MonthsDtos = _supplierMapper.Map <IEnumerable <MESES>, IEnumerable <MonthsDto> >(months);
                    var languages = await connection.QueryAsync <IDIOMAS>(LanguageSelect);

                    LanguageDtos = _supplierMapper.Map <IEnumerable <IDIOMAS>, IEnumerable <LanguageDto> >(languages);
                    var paymentForms = await connection.QueryAsync <FORMAS>(PaymentFormSelect);

                    PaymentDtos = _supplierMapper.Map <IEnumerable <FORMAS>, IEnumerable <PaymentFormDto> >(paymentForms);
                    var currency = await connection.QueryAsync <DIVISAS>(CurrencySelect);

                    CurrencyDtos = _supplierMapper.Map <IEnumerable <DIVISAS>, IEnumerable <CurrencyDto> >(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 <DeliveringFormDto> >(deliveringForm);
                    }
                    if (_supplierValue.VIA.HasValue)
                    {
                        //    var viaForm = await BuildAndExecute<VIAS>(connection, GenericSql.Via, _supplierValue?.VIA.Value)
                    }

                    var cityMapper = globalMapper;
                    var cityQuery  = string.Format(_queryCity);
                    var cities     = await connection.QueryAsync <POBLACIONES>(cityQuery);

                    var mappedCityDtos = cityMapper.Map <IEnumerable <POBLACIONES>, IEnumerable <CityDto> >(cities);
                    CityDtos = new ObservableCollection <CityDto>(mappedCityDtos);
                    // office mapping
                    string query  = string.Format(OfficeSelect, _supplierValue.OFICINA, _supplierValue.SUBLICEN);
                    var    office = await connection.QueryAsync <OFICINAS>(query);

                    var mappedOffices = MapperField.GetMapper().Map <IEnumerable <OFICINAS>, IEnumerable <OfficeDtos> >(office);
                    OfficeDtos = new ObservableCollection <OfficeDtos>(mappedOffices);
                    query      = string.Format(CompanySelect, _supplierValue.SUBLICEN);

                    var company = await connection.QueryAsync <SUBLICEN>(query);

                    CompanyDtos = MapperField.GetMapper().Map <IEnumerable <SUBLICEN>, IEnumerable <CompanyDto> >(company);
                    Value       = _supplierMapper.Map <SupplierPoco, SupplierDto>(_supplierValue);
                    Valid       = true;
                }
                catch (System.Exception e)
                {
                    throw new DataLayerExecutionException("Cannot load supplier " + e.Message);
                }
            }
            return(Valid);
        }