public IEnumerable <PartCommand> GetPartCommands()
        {
            var command = connection.CreateCommand();

            command.CommandText = @"SELECT 
          Id, PartTypeId, Count, Command 
        FROM PartCommand
        ORDER BY Id";
            var reader       = command.ExecuteReader();
            var partCommands = new List <PartCommand>();

            while (reader.Read())
            {
                var cmd = new PartCommand()
                {
                    Id         = reader.GetInt32(0),
                    PartTypeId = reader.GetInt32(1),
                    PartCount  = reader.GetInt32(2),
                    Command    = (PartCountOperation)Enum.Parse(
                        typeof(PartCountOperation),
                        reader.GetString(3))
                };
                cmd.Part = Parts.Single(p => p.Id == cmd.PartTypeId);
                partCommands.Add(cmd);
            }

            return(partCommands.ToArray());
        }
        public void CreatePartCommand(PartCommand partCommand)
        {
            var command = connection.CreateCommand();

            command.CommandText = @"INSERT INTO PartCommand
        (PartTypeId, Count, Command)
        VALUES (@partTypeId, 
        @partCount, @command);
        SELECT last_insert_rowid();";
            AddParameter(command, "@partTypeId", partCommand.PartTypeId);
            AddParameter(command, "@partCount", partCommand.PartCount);
            AddParameter(command, "@command", partCommand.Command.ToString());
            long partCommandId = (long)command.ExecuteScalar();

            partCommand.Id = (int)partCommandId;
        }
        public async Task CreatePartCommand(PartCommand partCommand)
        {
            using (var command = _connection.CreateCommand())
            {
                command.CommandText =
                    @"INSERT INTO PartCommand
                    (PartTypeId, Count, Command)
                    VALUES
                    (@partTypeId, @partCount, @command);
                    
                    SELECT last_insert_rowid();"; // Ensure we get the id for last insertion

                AddParameter(command, "@partTypeId", partCommand.PartTypeId);
                AddParameter(command, "@partCount", partCommand.PartCount);
                AddParameter(command, "@command", partCommand.Command.ToString());

                var partCommandId = (long)await command.ExecuteScalarAsync();

                partCommand.Id = (int)partCommandId;
            }
        }
        public async Task <IEnumerable <PartCommand> > GetPartCommands()
        {
            using (var command = _connection.CreateCommand())
            {
                command.CommandText =
                    @"SELECT Id, PartTypeid, Count, Command
                    FROM PartCommand
                    ORDER BY Id";

                using (var reader = await command.ExecuteReaderAsync().ConfigureAwait(false))
                {
                    var partCommands = new List <PartCommand>();

                    while (await reader.ReadAsync().ConfigureAwait(false))
                    {
                        var pc = new PartCommand()
                        {
                            Id         = reader.GetInt32(0),
                            PartTypeId = reader.GetInt32(1),
                            PartCount  = reader.GetInt32(2)
                        };

                        if (Enum.TryParse <PartCountOperation>(reader.GetString(3), out PartCountOperation operation))
                        {
                            pc.Command = operation;
                        }

                        pc.Part = Parts.Single(p => p.Id == pc.PartTypeId);

                        partCommands.Add(pc);
                    }

                    return(partCommands);
                }
            }
        }