Esempio n. 1
0
        /// <summary>
        /// New commission agent id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ICommissionAgent NewCommissionAgent(string id)
        {
            Contract.Requires(id.Length > 0, "Id length shall be ok.");
            CommissionAgent agent = new CommissionAgent(_sqlExecutor, id);

            return(agent);
        }
Esempio n. 2
0
        /// <summary>
        /// Create a list of commission agents
        /// </summary>
        /// <param name="fields">Fields to be fetched</param>
        /// <param name="maxLimit">Limit maximum of the agents to be fetched. Zero all fields</param>
        /// <param name="offset">Starting offset from which we can fetch</param>
        /// <returns>A list of commission agent objects.</returns>
        public async Task <IList <ICommissionAgent> > CreateCommissionAgentList(
            IDictionary <string, string> fields, int maxLimit = 0, int offset = 0)
        {
            Contract.Requires(fields.Count > 0, "Fields not valid");
            Contract.Requires(_sqlExecutor.Connection != null, "Null Connection");
            logger.Debug("Creating Commission List.");
            IDbConnection            connection        = _sqlExecutor.Connection;
            string                   currentQueryAgent = "";
            IList <ICommissionAgent> list = new List <ICommissionAgent>();

            if (maxLimit == 0)
            {
                currentQueryAgent = string.Format(CommissionAgentIds, fields["COMISIO"]);
            }
            else
            {
                currentQueryAgent = string.Format(CommissionAgentLimitsId, maxLimit, offset, fields["COMISIO"]);
            }
            logger.Debug("Current Agent Query :" + currentQueryAgent);
            using (connection)
            {
                logger.Debug("Create Loading CommissionAgent");
                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                }
                IEnumerable <COMISIO> commissionAgents = await connection.QueryAsync <COMISIO>(currentQueryAgent);

                foreach (COMISIO c in commissionAgents)
                {
                    CommissionAgent agent  = new CommissionAgent(_sqlExecutor);
                    bool            loaded = await agent.LoadValue(fields, c.NUM_COMI);

                    if (loaded)
                    {
                        logger.Debug("Agent Loaded.");
                        list.Add(agent);
                    }
                    else
                    {
                        logger.Info("Failed to laod the commission agent list.");
                    }
                }
            }
            return(list);
        }
Esempio n. 3
0
        /// <summary>
        /// This retrieve a commission agent.
        /// </summary>
        /// <param name="fields">Fields to be selected in the db</param>
        /// <param name="commissionId">Commission Id</param>
        /// <returns>A commmission agent data transfer object</returns>
        public async Task <ICommissionAgent> GetCommissionAgent(IDictionary <string, string> fields, string commissionId)
        {
            Contract.Requires(fields.Count > 0, "Fields not valid");
            Contract.Requires(!string.IsNullOrEmpty(commissionId), "Null Connection");
            CommissionAgent agent = new CommissionAgent(_sqlExecutor);

            logger.Debug("Loading CommissionAgent Value for id: " + commissionId);

            bool loaded = await agent.LoadValue(fields, commissionId).ConfigureAwait(false);

            agent.Valid = loaded;
            if (!agent.Valid)
            {
                logger.Info("Cannot Load Agent for ID" + commissionId + ".");
            }

            return(agent);
        }