示例#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());
            }
        }
示例#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();
            }
        }
示例#3
0
 public void Insert(Task.DTO.TaskDTO task)
 {
     TransactionUtil.DoTransactional(t => ExecuteInsert(task, t));
 }
示例#4
0
 public void Update(Task.DTO.TaskDTO task)
 {
     TransactionUtil.DoTransactional(t => ExecuteUpdate(task, t));
 }