Пример #1
0
        public Collection <T> ReadCollection(int id)
        {
            Collection <T> collection = new Collection <T>();

            using (IDbConnection connection = GetConnection())
            {
                IDbCommand command = connection.CreateCommand();
                command.Connection  = connection;
                command.CommandText = this.CommandText;
                command.CommandType = this.CommandType;

                foreach (IDataParameter param in this.GetParameters(command, id))
                {
                    command.Parameters.Add(param);
                }

                try
                {
                    connection.Open();

                    using (IDataReader reader = command.ExecuteReader())
                    {
                        try
                        {
                            MapperBase <T> mapper = GetMapper();
                            collection = mapper.MapAll(reader);
                            return(collection);
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            reader.Close();
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Пример #2
0
        public override Collection <Checkinout> ReadCollectionBy2Params(string userId, string fecha)
        {
            Collection <Checkinout> collection = new Collection <Checkinout>();

            using (IDbConnection connection = GetConnection())
            {
                IDbCommand command = connection.CreateCommand();
                command.Connection  = connection;
                command.CommandText = this.CommandText;
                command.CommandType = this.CommandType;

                foreach (IDataParameter param in this.GetParameters(command))
                {
                    command.Parameters.Add(param);
                }

                // Creando Parametro para filtrar por userId y fecha
                IDataParameter param1 = command.CreateParameter();
                param1.ParameterName = Constants.FilterOneParam;
                param1.DbType        = DbType.String;
                param1.Value         = userId;
                command.Parameters.Add(param1);

                param1 = command.CreateParameter();
                param1.ParameterName = Constants.FilterTwoParam;
                param1.DbType        = DbType.String;
                param1.Value         = fecha;
                //Console.WriteLine("Fecha: " + fecha.ToString("yyyyMMdd"));

                command.Parameters.Add(param1);

                try
                {
                    connection.Open();

                    using (IDataReader reader = command.ExecuteReader())
                    {
                        try
                        {
                            MapperBase <Checkinout> mapper = GetMapper();
                            collection = mapper.MapAll(reader);
                            return(collection);
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            reader.Close();
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }