Exemple #1
0
        /// <summary>
        /// Update unique block collection in database
        /// </summary>
        /// <param name="collection"></param>
        public void UpdateCollection(UniqueBlockCollection collection)
        {
            DbCommand command = factory.CreateCommand();

            if (command == null)
            {
                Console.WriteLine("CreateCommand error");
                throw new Exception("CreateCommand error");
            }

            command.Connection  = connection;
            command.CommandText = sqlUpdateCollection;

            DbParameter param = command.CreateParameter();

            param.ParameterName = "@id";
            param.Value         = collection.ID.ToString();
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@level1_blocks";
            param.Value         = ActiveBlocksToString(collection.Level1Blocks);
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@level2_blocks";
            param.Value         = ActiveBlocksToString(collection.Level2Blocks);
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@level3_blocks";
            param.Value         = ActiveBlocksToString(collection.Level3Blocks);
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@blocks";
            param.Value         = BlocksToString(collection.Collection);
            command.Parameters.Add(param);

            command.ExecuteNonQuery();
        }
Exemple #2
0
        /// <summary>
        /// Returns collection by its id
        /// </summary>
        public UniqueBlockCollection GetCollection(Guid collectionID)
        {
            DbCommand command = factory.CreateCommand();

            if (command == null)
            {
                Console.WriteLine("CreateCommand error");
                throw new Exception("CreateCommand error");
            }

            command.Connection  = connection;
            command.CommandText = sqlGetCollection;

            DbParameter param = command.CreateParameter();

            param.ParameterName = "@id";
            param.Value         = collectionID;
            command.Parameters.Add(param);

            using (DbDataReader dataReader = command.ExecuteReader())
            {
                if (!dataReader.Read())
                {
                    return(null);
                }

                UniqueBlockCollection collection = new UniqueBlockCollection();
                collection.ID           = (Guid)dataReader[nameof(Player.ID)];
                collection.Level1Blocks = ActiveBlocksFromString((string)dataReader[nameof(UniqueBlockCollection.Level1Blocks)]);
                collection.Level2Blocks = ActiveBlocksFromString((string)dataReader[nameof(UniqueBlockCollection.Level2Blocks)]);
                collection.Level3Blocks = ActiveBlocksFromString((string)dataReader[nameof(UniqueBlockCollection.Level3Blocks)]);
                collection.Collection   = BlocksFromString((string)dataReader[nameof(UniqueBlockCollection.Collection)]).ToList();

                return(collection);
            }
        }