| | 1 | | using Microsoft.Crm.Sdk.Messages; |
| | 2 | | using Microsoft.Xrm.Sdk; |
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.ServiceModel; |
| | 6 | |
|
| | 7 | | namespace FakeXrmEasy.FakeMessageExecutors |
| | 8 | | { |
| | 9 | | public class AssignRequestExecutor : IFakeMessageExecutor |
| | 10 | | { |
| | 11 | | public bool CanExecute(OrganizationRequest request) |
| 12 | 12 | | { |
| 12 | 13 | | return request is AssignRequest; |
| 12 | 14 | | } |
| | 15 | |
|
| | 16 | | public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx) |
| 30 | 17 | | { |
| 30 | 18 | | var assignRequest = (AssignRequest)request; |
| | 19 | |
|
| 30 | 20 | | var target = assignRequest.Target; |
| 30 | 21 | | var assignee = assignRequest.Assignee; |
| | 22 | |
|
| 30 | 23 | | if (target == null) |
| 6 | 24 | | { |
| 6 | 25 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not assign witho |
| | 26 | | } |
| | 27 | |
|
| 24 | 28 | | if (assignee == null) |
| 6 | 29 | | { |
| 6 | 30 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not assign witho |
| | 31 | | } |
| | 32 | |
|
| 18 | 33 | | var service = ctx.GetOrganizationService(); |
| | 34 | |
|
| 18 | 35 | | KeyValuePair<string, object> owningX = new KeyValuePair<string, object>(); |
| 18 | 36 | | if (assignee.LogicalName == "systemuser") |
| 12 | 37 | | owningX = new KeyValuePair<string, object>("owninguser", assignee); |
| 6 | 38 | | else if (assignee.LogicalName == "team") |
| 6 | 39 | | owningX = new KeyValuePair<string, object>("owningteam", assignee); |
| | 40 | |
|
| 18 | 41 | | var assignment = new Entity |
| 18 | 42 | | { |
| 18 | 43 | | LogicalName = target.LogicalName, |
| 18 | 44 | | Id = target.Id, |
| 18 | 45 | | Attributes = new AttributeCollection |
| 18 | 46 | | { |
| 18 | 47 | | { "ownerid", assignee }, |
| 18 | 48 | | owningX |
| 18 | 49 | | } |
| 18 | 50 | | }; |
| | 51 | |
|
| 18 | 52 | | service.Update(assignment); |
| | 53 | |
|
| 18 | 54 | | return new AssignResponse(); |
| 18 | 55 | | } |
| | 56 | |
|
| | 57 | | public Type GetResponsibleRequestType() |
| 4270 | 58 | | { |
| 4270 | 59 | | return typeof(AssignRequest); |
| 4270 | 60 | | } |
| | 61 | | } |
| | 62 | | } |