CommerceUpdate

This operation is used to update an existing commerce entity, update a related commerce entity of an existing commerce entity, or create, delete or update related commerce entities and relationships.

Dd328404.817534b7-e4d2-4d3f-8f16-a8eb9a92ed87(en-US,CS.90).gif

Class

Description

CommerceOperation

Base class of every operation.

PropertyDescription
ModelThis property represents the commerce entity of the operation. An example is the update of a UserProfile.
RelatedOperationsThis list represents commerce entities that are related to the Model. An example is the update of an Address for an existing UserProfile.

CommerceUpdateOperation

This is the concrete update operation class.

PropertyDescription
SearchCriteriaThis property specifies the commerce entity being updated.

CommerceUpdateOptions

The CommerceUpdateOptions can be specified as part of the CommerceUpdateOperation class definition.

PropertyDescription
ReturnModelThis property identifies the properties of the commerce entity to be returned as part of the response. A null indicates nothing is returned.
ReturnModelQueriesThis list identifies the relationships of the commerce entity to be returned as part of the response that should be populated. If ReturnModel is null, this property has no effect on the response.

CommerceRelatedOperation (Abstract)

Base class for every type of supported related item.

PropertyDescription
ModelThis property represents the related commerce entity.
RelationshipNameThis property indicates which collection the commerce entity belongs to. An example is the Address collection of the UserProfile.
SearchCriteriaThis property identifies the search information used to locate the related commerce entity being processed.
RelatedOperationsThis property specifies child relationships of the commerce entity.

CommerceUpdateRelatedItem

The CommerceUpdateRelatedItem indicates the update of an existing related item.

CommerceUpdateRelationship

The CommerceUpdateRelationship indicates the update will act on the relationship information only.

CommerceDeleteRelatedItem

The CommerceDeleteRelatedItem indicates a request to delete an existing related commerce entity.

CommerceDeleteRelationship

The CommerceDeleteRelationship indicates that only the relationship that exists should be deleted. The related commerce entity will not be deleted.

CommerceCreateRelatedItem

The CommerceCreateRelatedItem indicates a request to create a new related item commerce entity.

CommerceCreateRelationship

The CommerceCreateRelationship indicates a new relationship is being created between the commerce entity represented by the Model and an existing commerce entity represented by RelatedOperation.SearchCriteria.

CommerceCopyRelatedItem

The CommerceCopyRelatedItem is used to copy commerce entity information from another commerce entity to the one specified by the operation. An example scenario is where credit card information is copied from the UserProfile into the Basket.

Restrictions

If the parent search criteria or the search criteria of a related commerce entity select anything other than a single commerce entity, the system will throw an exception. The system will also throw an exception if the SearchCriteria type is not supported. Also, only one top-level commerce entity can be updated at a time.

Response

Running a CommerceUpdateOperation request creates a CommerceUpdateOperationResponse.

Dd328404.cefbcf38-9219-4ee9-9a8d-0321afa564e0(en-US,CS.90).gif

Class

Description

CommerceOperationResponse

Base class for every operation.

CommercesUpdateOperationResponse

Response of a CommerceUpdateOperation.

PropertyDescription
CountThis property indicates the number of items that were updated. This count also includes any updated, deleted and created related item or relationships. The Count Return the updated commerce entity if a ReturnModel has been specified in the options. This will manifest itself in the CommerceEntities property. This is also true for any updated related commerce entity.
CommerceEntitiesThis property This list represents the commerce entities returned as part of the CommerceUpdateOperation.

CommerceUpdate<> Generic Class

The CommerceUpdate<> generic class constructs a CommerceUpdateOperation operation or request to send to Microsoft Multi-Channel Commerce Foundation.

Dd328404.f7297bf7-453a-4073-9bc4-8d9a2c551e3e(en-US,CS.90).gif

Property

Description

CommerceUpdate<TItem, TSearch, TOption>

Generic class used to create a request for the CommerceUpdateOperation.

PropertyDescription
TItemThis item represents the commerce entity type (i.e. the Model) of the update operation.
TSearchThis item represents the SearchCriteria type used to find the top level commerce entity.
TOptionsThis item represents the type of CommerceUpdateOptions to be sent as part of the CommerceRequest.

CommerceUpdate<TItem, TSearch>

Generic class used to create a request for the CommerceUpdateOperation.

PropertyDescription
TItemThis item represents the commerce entity type (i.e. the Model) of the update operation. TOption is defaulted to CommerceUpdateOptionBuilder<TItem> which represents the default CommerceUpdateOptions message.
TSearchThis item represents the SearchCriteria type used to find the top level commerce entity. The CommerceSearchCriteria is defaulted to CommerceModelSearch of the model represented by TItem.

CommerceUpdate<TItem>

Generic class used to create a request for the CommerceUpdateOperation.

PropertyDescription
TItemThis item represents the commerce entity type (i.e. the Model) of the update operation.

CommerceUpdateRelatedItem<TItem>

Generic class used to update an existing related commerce entity.

PropertyDescription
TItemThis item represents the related commerce entity type. The relationship data type is defaulted to Relationship.

CommerceUpdateRelationship<TItem, TRelationship>

Generic class used to update the content of a relationship.

PropertyDescription
TItemThis item represents the commerce entity of the relationship.
TRelationshipThis item represents the data type of the relationship.

CommerceUpdateRelationship<TItem>

Generic class used to update the content of a relationship.

PropertyDescription
TItemThis item represents the commerce entity of the relationship. The relationship data type is defaulted to Relationship.

CommerceDeleteRelatedItem<TItem>

Generic class used to delete an existing related commerce entity.

PropertyDescription
TItemThis item represents the related commerce entity type.

CommerceDeleteRelationship<TItem, TRelationship>

Generic class used to delete a relationship between the parent entity and an existing related item.

PropertyDescription
TItemThis item represents the commerce entity of the relationship.
TRelationshipThis item represents the data type of the relationship.

CommerceDeleteRelationship<TItem>

Generic class used to delete a relationship between the parent entity and an existing related item.

PropertyDescription
TItemThis item represents the commerce entity of the relationship. The relationship data type is defaulted to Relationship.

CommerceCreateRelationship<TItem, TRelationship>

Generic class used to create a relationship between the parent commerce entity and an existing related item.

PropertyDescription
TItemThis item represents the commerce entity of the relationship.
TRelationshipThis item represents the data type of the relationship.

CommerceCreateRelationship<TItem>

Generic class used to create a relationship between the parent commerce entity and an existing related item.

PropertyDescription
TItemThis item represents the commerce entity of the relationship. The relationship data type is defaulted to Relationship.

CommerceCreateRelatedItem<TItem>

Generic class used to create a new related commerce entity.

PropertyDescription
TItemThis item represents the related commerce entity type.

CommerceCopyRelatedItem<TItem, TParent>

Generic class used to copy commerce entity information from another commerce entity to the one specified by the operation. An example scenario is where credit card information is copied from the UserProfile into the Basket.

PropertyDescription
TItemThis item represents the related commerce entity to copy from.
TParentThis item represents the parent of TItem.

CommerceCopyRelatedItem<TItem >

Generic class used to copy commerce entity information from another commerce entity to the one specified by the operation. An example scenario is where credit card information is copied from the UserProfile into the Basket.

PropertyDescription
TItemThis item represents the related commerce entity to copy from.

Example

The following example updates the quantity of a LineItem related to a Basket.

// The example first constructs a CommerceUpdate<> object. The first parameter 
// to the generic class indetifies the commerce entity type. Notice how the 
// parent of the LineItem is used in the update operation (i.e. the Basket). 
// This is consistent across all operations.
// 
// The second parameter is the type of search that is used to find the Basket 
// commerce entity. In the example above, a ModelSearch is used which expresses 
// the query through the Model.
Var updateBasket = new CommerceUpdate<CommerceEntity>("Basket");

// Provide the search criteria to identify the basket
updateBasket.SearchCriteria.Model.Properties.Add("Name","Default");
updateBasket.SearchCriteria.Model.Id = base.UserId;
updateBasket.SearchCriteria.Model.Properties.Add("BasketType", 0);

// Create an UpdateRelatedItem<> providing it the LineItem type. Set 
// the search criteria information to locate the LineItem and add the object to 
// the related items list of the operation.
var lineItemToUpdate = new CommerceUpdateRelatedItem<CommerceEntity>(
    "LineItems"
    "LineItem");

lineItemToUpdate.SearchCriteria.Model.Id = lineitemId;
lineItemToUpdate.Model.Quantity = 2;

updateBasket.RelatedOperations.Add(lineItemToUpdate);

// ProcessRequest(updateBasket.ToRequest()) sends the UpdateOperation to Commerce Foundation 
// which returns a Response. Operation responses are always returned in the same 
// order as the operation requests. Since there is a single operation for the 
// request, the operation response is located in index 0 of the 
// response.OperationResponses.
CommerceResponse response = 
    OperationService.ProcessRequest(base.GetCurrentRequestContext(), 
                                   updateBasket.ToRequest());

CommerceUpdateOperationResponse updateResponse =
    response.OperationResponses[0] as CommerceUpdateOperationResponse;

Assert.Equals(updateResponse.Count, 1);

See Also

Other Resources

Developing with the Multi-Channel Commerce Foundation

Commerce Foundation Operations