Example #1
0
 internal static csc_VolunteerApplication GetVolunteerApplicationEntity(this ICrmServiceContext apiController,
                                                                        Guid volunteerApplicationId, Guid volunteerId)
 {
     return((from volunteerApplicationEntity in apiController.GetCrmServiceContext().csc_VolunteerApplicationSet
             where volunteerApplicationEntity.csc_Volunteer.Id.Equals(volunteerId)
             where volunteerApplicationEntity.Id.Equals(volunteerApplicationId)
             select volunteerApplicationEntity).Single());
 }
        public void RemoveCachedData_ShouldNotCallRemoveOfOrganizationServiceCache_WhenContextIsOfWrongType()
        {
            var contextMock = new Mock<ICrmServiceContext>();
            m_context = contextMock.Object;

            m_context.RemoveCachedData(TestName, TestGuid);

            m_serviceCacheMock.Verify(x => x.Remove(It.IsAny<string>(), It.IsAny<Guid?>()), Times.Never);
        }
        public void RemoveCachedData_ShouldNotCallRemoveOfOrganizationServiceCache_WhenInternalServiceIsNotOfCachedOrganizationServiceType()
        {
            var contextMock = new Mock<ICrmServiceContext>();
            contextMock.As<IOrganizationServiceContainer>().SetupGet(x => x.Service).Returns((IOrganizationService)null);
            m_context = contextMock.Object;

            m_context.RemoveCachedData(TestName, TestGuid);

            m_serviceCacheMock.Verify(x => x.Remove(It.IsAny<string>(), It.IsAny<Guid?>()), Times.Never);
        }
        public void RemoveCachedData_ShouldCallRemoveOfOrganizationServiceCache_WhenOrganizationServiceCacheIsConfigured()
        {
            var contextMock = new Mock<ICrmServiceContext>();
            contextMock.As<IOrganizationServiceContainer>().SetupGet(x => x.Service)
                       .Returns(new CachedOrganizationService("Xrm", m_serviceCacheMock.Object));
            m_context = contextMock.Object;

            m_context.RemoveCachedData(TestName, TestGuid);

            m_serviceCacheMock.Verify(x => x.Remove(TestName, TestGuid), Times.Once);
        }
Example #5
0
        public static void Execute(ICurrencyExchanger exchanger, ICrmServiceContext ctx)
        {
            // Get Open exchange rates
            var exchangeRates = exchanger.GetExchangeRates();

            // Nice to have logging code. Indicates if OpenExchange.org is working or not.
            foreach (var rate in exchangeRates)
            {
                Console.WriteLine($"{rate.Key}: {rate.Value}");
            }

            // Get base currency
            var baseIso = ctx.OrganizationSet
                          .Join(
                ctx.TransactionCurrencySet,
                o => o.BaseCurrencyId.Id,
                c => c.TransactionCurrencyId,
                (o, c) => new { o, c })
                          .Select(j => j.c.ISOCurrencyCode)
                          .First();

            Console.WriteLine($"Base ISO: {baseIso}");

            decimal baseCurrencyRate = exchangeRates[baseIso];

            var currencies = ctx.TransactionCurrencySet
                             .Select(c => new TransactionCurrency()
            {
                TransactionCurrencyId = c.TransactionCurrencyId,
                ISOCurrencyCode       = c.ISOCurrencyCode
            }).ToArray();

            foreach (var c in currencies)
            {
                if (c.ISOCurrencyCode == baseIso)
                {
                    continue;
                }

                var rate = exchangeRates[c.ISOCurrencyCode] / baseCurrencyRate;

                ctx.Execute(new UpdateRequest()
                {
                    Target = new TransactionCurrency()
                    {
                        TransactionCurrencyId = c.TransactionCurrencyId,
                        ExchangeRate          = rate
                    }
                });

                Console.WriteLine($"Update D365 currency {c.ISOCurrencyCode} exchange rate to {rate}");
            }
        }