Exemplo n.º 1
0
        /// <summary>
        ///  Create a local query store.
        /// </summary>
        /// <param name="company">Company data transfer object used to be inserted in the query store.</param>
        /// <returns>Return an interface of the query store.</returns>
        private IQueryStore CreateQueryStore(CompanyViewObject company)
        {
            IQueryStore store = _queryStoreFactory.GetQueryStore();

            store.Clear();
            store.AddParamCount(QueryType.QueryCity, company.CP);
            store.AddParamCount(QueryType.QueryProvince, company.PROVINCIA);
            store.AddParamCount(QueryType.QueryCompanyOffices, company.Code);
            return(store);
        }
Exemplo n.º 2
0
        public void Should_Build_QueryFromQueryStoreWithNullParameters2()
        {
            CompanyDto dto = new CompanyDto
            {
                CP        = null,
                PROVINCIA = null,
                Code      = "282998"
            };
            IQueryStore store = _storeFactory.GetQueryStore();

            store.Clear();
            store.AddParam(QueryType.QueryCity, dto.CP);
            store.AddParam(QueryType.QueryProvince, dto.PROVINCIA);
            store.AddParam(QueryType.QueryCompanyOffices,
                           dto.Code);
            var q = store.BuildQuery();

            Assert.AreEqual(q, Query3);
        }
Exemplo n.º 3
0
        public void Should_Build_QueryFromQueryStoreWithNullParameters()
        {
            CompanyViewObject viewObject = new CompanyViewObject
            {
                CP        = "1892829",
                PROVINCIA = null,
                Code      = "282998"
            };
            IQueryStore store = _storeFactory.GetQueryStore();

            store.Clear();
            store.AddParam(QueryType.QueryCity, viewObject.CP);
            store.AddParam(QueryType.QueryProvince, viewObject.PROVINCIA);
            store.AddParam(QueryType.QueryCompanyOffices,
                           viewObject.Code);
            var q = store.BuildQuery();

            Assert.AreEqual(q, Query2);
        }
Exemplo n.º 4
0
        /// <summary>
        ///  Load single value. It loads a commission agent.
        /// </summary>
        /// <param name="commissionDictionary">Dictionary of the selected fields</param>
        /// <param name="commissionId"></param>
        /// <returns></returns>
        public async Task <bool> LoadValue(IDictionary <string, string> commissionDictionary, string commissionId)
        {
            // in the commission query already i have a commission id.
            bool preCondition = commissionDictionary.ContainsKey(Comisio);

            Contract.Requires(preCondition, "The dictionary used is not correct");
            Contract.Requires(!string.IsNullOrEmpty(commissionId), "The commission is is not ok");
            logger.Info("Load Agent for ID" + commissionId);

            string commisionQueryFields = commissionDictionary[Comisio];
            string tipoComiFields       = GetFields(Tipocomi, commissionDictionary, DefaultTicomiFields);
            string branchesField        = GetFields(Branches, commissionDictionary, DefaultDelegation);
            // this collect all kind of objects as result of the query.
            bool isOpen = false;

            if (_dbConnection == null)
            {
                logger.Debug("Opening Connection to DB");
                isOpen = _executor.Open();
            }
            // now between the two

            // TODO: all this is pretty slow. Just use query store and load it.
            IQueryStore store = _queryStoreFactory.GetQueryStore();

            if (isOpen)
            {
                try
                {
                    _dbConnection = _executor.Connection;
                    string commisionQuery = string.Format(_queryComi, commisionQueryFields, commissionId);
                    logger.Debug("Executing query " + commisionQuery);

                    _commissionAgents = await _dbConnection.QueryAsync <COMISIO>(commisionQuery);

                    _currentComisio = _commissionAgents.FirstOrDefault();

                    if (_currentComisio != null)
                    {
                        if (!string.IsNullOrEmpty(_currentComisio.PROVINCIA))
                        {
                            string provinceQuery = string.Format(_queryProvincia, _currentComisio.PROVINCIA);
                            _provinces = await _dbConnection.QueryAsync <PROVINCIA>(provinceQuery).ConfigureAwait(false);

                            ProvinceDto = _mapper.Map <IEnumerable <PROVINCIA>, IEnumerable <ProvinciaDto> >(_provinces);
                        }
                        store.AddParam(QueryType.QueryBrokerContacts, _currentComisio.NUM_COMI);
                        var queryContactos = store.BuildQuery();
                        _contactos = await _dbConnection
                                     .QueryAsync <ContactsComiPoco>(queryContactos);

                        ContactsDto = _mapper.Map <IEnumerable <ContactsComiPoco>, IEnumerable <ContactsDto> >(_contactos);

                        string queryTipoComi = string.Format(_queryTipoComi, tipoComiFields, _currentComisio.TIPOCOMI);
                        logger.Debug("Query commission agent kind: " + queryTipoComi);

                        _tipoComis = await _dbConnection.QueryAsync <TIPOCOMI>(queryTipoComi).ConfigureAwait(false);

                        if (!string.IsNullOrEmpty(_currentComisio.NACIOPER))
                        {
                            string queryPais = string.Format(_queryPais, _currentComisio.NACIOPER);
                            logger.Debug("Query commission agent kind: " + queryPais);
                            _nacioPer = await _dbConnection.QueryAsync <Country>(queryPais);

                            CountryDto = _mapper.Map <IEnumerable <Country>, IEnumerable <CountryDto> >(_nacioPer);
                        }

                        string delega = string.Format(_queryComiDelega, branchesField, _currentComisio.NUM_COMI);
                        _delegations = await _dbConnection.QueryAsync <ComiDelegaPoco, PROVINCIA, ComiDelegaPoco>(delega,
                                                                                                                  (branch, prov) =>
                        {
                            branch.PROV = prov;
                            return(branch);
                        }, splitOn : "SIGLAS");

                        BranchesDto = _mapper.Map <IEnumerable <ComiDelegaPoco>, IEnumerable <BranchesDto> >(_delegations);
                        store.Clear();
                        store.AddParam(QueryType.QueryBrokerVisit, _currentComisio.NUM_COMI);
                        var visitas = store.BuildQuery();
                        _visitasComis = await _dbConnection.QueryAsync <VisitasComiPoco>(visitas);

                        VisitsDto = _mapper.Map <IEnumerable <VisitasComiPoco>, IEnumerable <VisitsDto> >(_visitasComis);
                        var visitType = await _dbConnection.GetAsyncAll <TIPOVISITAS>();

                        VisitTypeDto = _mapper.Map <IEnumerable <TIPOVISITAS>, IEnumerable <VisitTypeDto> >(visitType);

                        logger.Debug("Executing AuxQueries.");
                        await BuildAuxQueryMultiple(_currentComisio, _dbConnection);
                    }
                }
                catch (System.Exception e)
                {
                    logger.Info("Cannot open value" + e.Message);

                    return(false);
                }
                finally
                {
                    _executor.Close();
                    logger.Debug("Connection close with success.");
                }
            }
            else
            {
                logger.Debug("Current commisionist is null.");
                return(false);
            }
            _valid = true;
            return(true);
        }
Exemplo n.º 5
0
 /// <summary>
 ///  Clears a store
 /// </summary>
 /// <returns>The interface itself for creating a query.</returns>
 public override IQueryStore Clear()
 {
     _store.Clear();
     _builder.Clear();
     return(this);
 }