Beispiel #1
0
        public void ExecuteInsert(Task.DTO.TaskDTO task, SqlTransaction transaction)
        {
            using (var command = transaction.Connection.CreateCommand())
            {
                command.Transaction = transaction;
                command.CommandType = CommandType.Text;

                command.CommandText = @"
INSERT INTO Task
(
    CreatedDate
    ,RequiredByDate
    ,Description
    ,StatusID
    ,TypeID   
)
VALUES
(
    @CreatedDate
    ,@RequiredByDate
    ,@Description
    ,@StatusID
    ,@TypeID 
)
SELECT @@IDENTITY
";
                if (task.CreatedDate.HasValue)
                {
                    command.Parameters.AddWithValue("CreatedDate", task.CreatedDate);
                }
                else
                {
                    command.Parameters.AddWithValue("CreatedDate", DBNull.Value);
                }

                if (task.RequiredByDate.HasValue)
                {
                    command.Parameters.AddWithValue("RequiredByDate", task.RequiredByDate);
                }
                else
                {
                    command.Parameters.AddWithValue("RequiredByDate", DBNull.Value);
                }

                command.Parameters.AddWithValue("Description", task.Description);
                command.Parameters.AddWithValue("StatusID", task.TaskStatusId);
                command.Parameters.AddWithValue("TypeID", task.TaskTypeID);

                task.ID = Convert.ToInt32(command.ExecuteScalar());
            }
        }
Beispiel #2
0
        public void ExecuteUpdate(Task.DTO.TaskDTO task, SqlTransaction transaction)
        {
            using (var command = transaction.Connection.CreateCommand())
            {
                command.Transaction = transaction;
                command.CommandType = CommandType.Text;

                command.CommandText = @"
UPDATE Task
SET
    CreatedDate = @CreatedDate
    ,RequiredByDate = @RequiredByDate
    ,Description = @Description
    ,StatusID = @StatusID
    ,TypeID = @TypeID
WHERE 
    ID = @ID";

                command.Parameters.AddWithValue("ID", task.ID);

                //CreatedDate
                if (task.CreatedDate.HasValue)
                {
                    command.Parameters.AddWithValue("CreatedDate", task.CreatedDate);
                }
                else
                {
                    command.Parameters.AddWithValue("CreatedDate", DBNull.Value);
                }

                //RequiredByDate
                if (task.RequiredByDate.HasValue)
                {
                    command.Parameters.AddWithValue("RequiredByDate", task.RequiredByDate);
                }
                else
                {
                    command.Parameters.AddWithValue("RequiredByDate", DBNull.Value);
                }

                command.Parameters.AddWithValue("Description", task.Description);
                command.Parameters.AddWithValue("StatusID", task.TaskStatusId);
                command.Parameters.AddWithValue("TypeID", task.TaskTypeID);

                command.ExecuteNonQuery();
            }
        }
Beispiel #3
0
 public void Insert(Task.DTO.TaskDTO task)
 {
     TransactionUtil.DoTransactional(t => ExecuteInsert(task, t));
 }
Beispiel #4
0
 public void Update(Task.DTO.TaskDTO task)
 {
     TransactionUtil.DoTransactional(t => ExecuteUpdate(task, t));
 }