コード例 #1
0
        public async Task Should_Load_BrokerVisitCorrectly()
        {
            using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection())
            {
                // arrange
                var brokers = await connection.GetAllAsync <COMISIO>();

                var contactsBroker = await connection.QueryAsync <CONTACTOS_COMI>("select * from contactos_comi");

                var        singleBroker = brokers.FirstOrDefault();
                QueryStore store        = QueryStore.GetInstance();
                store.Clear();
                store.AddParam(QueryType.QueryClientVisits, singleBroker.NUM_COMI);
                var query = store.BuildQuery();
                // act
                var visitasComi = await connection.QueryAsync <VisitasComiPoco>(query);

                // assert.
                Assert.NotNull(visitasComi);
                var count = visitasComi.Count();
                Assert.GreaterOrEqual(count, 0);
                if (count > 0)
                {
                    foreach (var v in visitasComi)
                    {
                        Assert.NotNull(v.VisitId);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Get a paged version of the summary.
        /// </summary>
        /// <param name="pageSize">Page dimension.</param>
        /// <param name="offset">Offset</param>
        /// <returns></returns>
        public async Task <IEnumerable <VehicleSummaryDto> > GetVehiclesAgentSummary(int pageSize, int offset)
        {
            // TODO: Fix the usage of the query store.
            QueryStore store = new QueryStore();


            new QueryStore();
            IEnumerable <VehicleSummaryDto> vehicles = null;
            string value = "";

            if (pageSize == 0)
            {
                store.AddParam(QueryType.QueryVehicleSummary);
                value = store.BuildQuery();
            }
            else
            {
                store.Clear();
                store.AddParamRange(QueryType.QueryVehicleSummaryPaged, pageSize, offset);
                var query = store.BuildQuery();
            }
            using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection())
            {
                /*
                 *  Move to query store.
                 */
                vehicles = await connection.QueryAsync <VehicleSummaryDto>(GenericSql.VehiclesSummaryQuery);
            }
            return(vehicles);
        }
コード例 #3
0
        public void Should_Trigger_ANewSummaryFilter()
        {
            IQueryFilter       queryFilter = new QueryFilter("NOMBRE", "CLA*", PredicateType.And);
            IDataFilterService dataFilter  = new DataFilterSummaryService <ClientSummaryExtended>(_dialogMock.Object, _executor);

            _queryStore.Clear();
            var query = queryFilter.Resolve();

            dataFilter.FilterEventResult += DataFilter_FilterEventResult;
            dataFilter.FilterDataAsync(query);
        }
コード例 #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.
            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);
                        }
                        QueryStore store = QueryStore.GetInstance();



                        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");

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

                        VisitDto = _mapper.Map <IEnumerable <VisitasComiPoco>, IEnumerable <VisitsDto> >(_visitasComis);
                        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);
        }