| | 1 | | using Microsoft.Crm.Sdk.Messages; |
| | 2 | | using Microsoft.Xrm.Sdk; |
| | 3 | | using System; |
| | 4 | |
|
| | 5 | | namespace FakeXrmEasy.FakeMessageExecutors |
| | 6 | | { |
| | 7 | | public class CloseQuoteRequestExecutor : IFakeMessageExecutor |
| | 8 | | { |
| | 9 | | public bool CanExecute(OrganizationRequest request) |
| 6 | 10 | | { |
| 6 | 11 | | return request is CloseQuoteRequest; |
| 6 | 12 | | } |
| | 13 | |
|
| | 14 | | public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx) |
| 6 | 15 | | { |
| 6 | 16 | | var closeRequest = request as CloseQuoteRequest; |
| | 17 | |
|
| 6 | 18 | | if (closeRequest == null) |
| 0 | 19 | | { |
| 0 | 20 | | throw new Exception("You did not pass a CloseQuoteRequest"); |
| | 21 | | } |
| | 22 | |
|
| 6 | 23 | | var quoteClose = closeRequest.QuoteClose; |
| | 24 | |
|
| 6 | 25 | | if (quoteClose == null) |
| 0 | 26 | | { |
| 0 | 27 | | throw new Exception("QuoteClose is mandatory"); |
| | 28 | | } |
| | 29 | |
|
| 6 | 30 | | var quoteId = quoteClose.GetAttributeValue<EntityReference>("quoteid"); |
| | 31 | |
|
| 6 | 32 | | if (quoteId == null) |
| 0 | 33 | | { |
| 0 | 34 | | throw new Exception("Quote ID is not set on QuoteClose, but is required"); |
| | 35 | | } |
| | 36 | |
|
| 6 | 37 | | var update = new Entity |
| 6 | 38 | | { |
| 6 | 39 | | Id = quoteId.Id, |
| 6 | 40 | | LogicalName = "quote", |
| 6 | 41 | | Attributes = new AttributeCollection |
| 6 | 42 | | { |
| 6 | 43 | | { "statuscode", closeRequest.Status } |
| 6 | 44 | | } |
| 6 | 45 | | }; |
| | 46 | |
|
| 6 | 47 | | var service = ctx.GetOrganizationService(); |
| | 48 | |
|
| 6 | 49 | | service.Update(update); |
| | 50 | |
|
| 6 | 51 | | return new CloseQuoteResponse(); |
| 6 | 52 | | } |
| | 53 | |
|
| | 54 | | public Type GetResponsibleRequestType() |
| 4270 | 55 | | { |
| 4270 | 56 | | return typeof(CloseQuoteRequest); |
| 4270 | 57 | | } |
| | 58 | | } |
| | 59 | | } |