BlueCollar.SQLiteRepository.CreateQueuedAndHistoryForSchedule C# (CSharp) Method

CreateQueuedAndHistoryForSchedule() public method

Creates the queue and history records for the given schedule.
public CreateQueuedAndHistoryForSchedule ( long scheduleId, System.DateTime scheduleDate, IEnumerable queued, IEnumerable history, IDbTransaction transaction ) : int
scheduleId long The ID of the schedule records are being created for.
scheduleDate System.DateTime The schedule date records are being created for.
queued IEnumerable The queued records to create.
history IEnumerable The history records to create.
transaction IDbTransaction The transaction to use, if applicable.
return int
        public int CreateQueuedAndHistoryForSchedule(long scheduleId, DateTime scheduleDate, IEnumerable<QueueRecord> queued, IEnumerable<HistoryRecord> history, IDbTransaction transaction)
        {
            int created = 0;
            bool commitRollback = false;

            if (transaction == null)
            {
                commitRollback = true;
                transaction = this.BeginTransaction();
            }

            try
            {
                const string InsertQueuedSql =
            @"INSERT INTO [BlueCollarQueue]([ApplicationName],[ScheduleId],[QueueName],[JobName],[JobType],[Data],[QueuedOn],[TryNumber])
            VALUES(@ApplicationName,@ScheduleId,@QueueName,@JobName,@JobType,@Data,@QueuedOn,@TryNumber);";

                const string InsertHistorySql =
            @"INSERT INTO [BlueCollarHistory]([ApplicationName],[WorkerId],[ScheduleId],[QueueName],[JobName],[JobType],[Data],[QueuedOn],[TryNumber],[StartedOn],[Status],[Exception],[FinishedOn])
            VALUES (@ApplicationName,@WorkerId,@ScheduleId,@QueueName,@JobName,@JobType,@Data,@QueuedOn,@TryNumber,@StartedOn,@StatusString,@Exception,@FinishedOn);";

                if (queued != null && queued.Count() > 0)
                {
                    created += this.connection.Execute(InsertQueuedSql, queued, transaction, null, null);
                }

                if (history != null && history.Count() > 0)
                {
                    created += this.connection.Execute(InsertHistorySql, history, transaction, null, null);
                }

                if (commitRollback)
                {
                    transaction.Commit();
                }
            }
            catch
            {
                if (commitRollback)
                {
                    transaction.Rollback();
                }

                throw;
            }
            finally
            {
                if (commitRollback)
                {
                    transaction.Dispose();
                }
            }

            return created;
        }