Created
October 10, 2018 20:17
-
-
Save websterian/69258ce70889ff5c6b043d14584b5186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using Sitecore.Commerce.Core; | |
using Sitecore.Commerce.EntityViews; | |
using Sitecore.Framework.Pipelines; | |
namespace Sitecore.Services.Examples.Entities.Pipelines.Blocks | |
{ | |
[PipelineDisplayName("DoActionRemoveBrandBlock")] | |
public class DoActionRemoveBrandBlock : PipelineBlock<EntityView, EntityView, CommercePipelineExecutionContext> | |
{ | |
private readonly CommerceCommander _commerceCommander; | |
public DoActionRemoveBrandBlock(CommerceCommander commerceCommander) | |
{ | |
_commerceCommander = commerceCommander; | |
} | |
public override async Task<EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context) | |
{ | |
var action = entityView?.Action; | |
if (string.IsNullOrEmpty(action) || !entityView.Action.Equals("RemoveBrand", StringComparison.OrdinalIgnoreCase)) | |
{ | |
return await Task.FromResult(entityView); | |
} | |
else | |
{ | |
var id = (string.IsNullOrEmpty(entityView.EntityId) ? entityView.ItemId : entityView.EntityId); | |
if (!string.IsNullOrEmpty(id)) | |
{ | |
//TODO : Add delete command, dont call pipeline directly | |
await _commerceCommander.Pipeline<IDeleteEntityPipeline>().Run(new DeleteEntityArgument(id), context); | |
return await Task.FromResult(entityView); | |
} | |
else | |
{ | |
var validationError = context.GetPolicy<KnownResultCodes>().ValidationError; | |
var objArray = new object[] { "EntityId" }; | |
await context.CommerceContext.AddMessage(validationError, "InvalidOrMissingPropertyValue", objArray, "Invalid or missing value for property 'EntityId'."); | |
return await Task.FromResult(entityView); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment