Created
April 14, 2017 12:46
-
-
Save pawelgradecki/23731bf5f44e1568d5bac3227977a767 to your computer and use it in GitHub Desktop.
BAD Early bound multientity plugin
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
public class CalculateTotalAmountEarlyBoundBADPlugin : IPlugin | |
{ | |
public void Execute(IServiceProvider serviceProvider) | |
{ | |
var context = serviceProvider.GetService(typeof(IPluginExecutionContext)) as IPluginExecutionContext; | |
var serviceFactory = serviceProvider.GetService(typeof(IOrganizationServiceFactory)) as IOrganizationServiceFactory; | |
var service = serviceFactory.CreateOrganizationService(context.UserId); | |
var lateBoundEntity = context.InputParameters["Target"] as Entity; | |
switch (lateBoundEntity.LogicalName) | |
{ | |
case Account.EntityLogicalName: | |
var account = lateBoundEntity.ToEntity<Account>(); | |
account.new_totalsum = account.new_netamount + account.new_margin; | |
break; | |
case Opportunity.EntityLogicalName: | |
var opportunity = lateBoundEntity.ToEntity<Opportunity>(); | |
opportunity.new_totalsum = opportunity.new_netamount + opportunity.new_margin; | |
break; | |
default: | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment