| | 1 | | using Microsoft.Crm.Sdk.Messages; |
| | 2 | | using Microsoft.Xrm.Sdk; |
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Linq; |
| | 6 | | using System.ServiceModel; |
| | 7 | | using Microsoft.Xrm.Sdk.Query; |
| | 8 | |
|
| | 9 | | namespace FakeXrmEasy.FakeMessageExecutors |
| | 10 | | { |
| | 11 | | public class RetrieveExchangeRateRequestExecutor : IFakeMessageExecutor |
| | 12 | | { |
| | 13 | | public bool CanExecute(OrganizationRequest request) |
| 0 | 14 | | { |
| 0 | 15 | | return request is RetrieveExchangeRateRequest; |
| 0 | 16 | | } |
| | 17 | |
|
| | 18 | | public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx) |
| 0 | 19 | | { |
| 0 | 20 | | var retrieveExchangeRateRequest = (RetrieveExchangeRateRequest)request; |
| | 21 | |
|
| 0 | 22 | | var currencyId = retrieveExchangeRateRequest.TransactionCurrencyId; |
| | 23 | |
|
| 0 | 24 | | if (currencyId == null) |
| | 25 | | { |
| | 26 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not retrieve Exc |
| | 27 | | } |
| | 28 | |
|
| 0 | 29 | | var service = ctx.GetOrganizationService(); |
| | 30 | |
|
| 0 | 31 | | var result = service.RetrieveMultiple(new QueryExpression("transactioncurrency") |
| 0 | 32 | | { |
| 0 | 33 | | ColumnSet = new ColumnSet("exchangerate"), |
| 0 | 34 | | Criteria = new FilterExpression |
| 0 | 35 | | { |
| 0 | 36 | | Conditions = |
| 0 | 37 | | { |
| 0 | 38 | | new ConditionExpression("transactioncurrencyid", ConditionOperator.Equal, currencyId) |
| 0 | 39 | | } |
| 0 | 40 | | } |
| 0 | 41 | | }).Entities; |
| | 42 | |
|
| 0 | 43 | | if (!result.Any()) |
| 0 | 44 | | { |
| 0 | 45 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Transaction Currency |
| | 46 | | } |
| | 47 | |
|
| 0 | 48 | | var exchangeRate = result.First().GetAttributeValue<decimal>("exchangerate"); |
| | 49 | |
|
| 0 | 50 | | return new RetrieveExchangeRateResponse |
| 0 | 51 | | { |
| 0 | 52 | | Results = new ParameterCollection |
| 0 | 53 | | { |
| 0 | 54 | | {"ExchangeRate", exchangeRate} |
| 0 | 55 | | } |
| 0 | 56 | | }; |
| 0 | 57 | | } |
| | 58 | |
|
| | 59 | | public Type GetResponsibleRequestType() |
| 4270 | 60 | | { |
| 4270 | 61 | | return typeof(RetrieveExchangeRateRequest); |
| 4270 | 62 | | } |
| | 63 | | } |
| | 64 | | } |