Esempio n. 1
0
        public Guid SaveConstituentInfo()
        {
            //if (this.BIRTHDATE.HasValue())
            //    this.ApplyBirthdateRule();
            //this.ApplyNameFormatsRule();
            //if (!this.MatchUpdated())
            //{
            //    int num = 0;
            //    DuplicateResolutionUIModel.BATCHTYPES? nullable1 = this.BATCHTYPE.Value;
            //    int? nullable2 = nullable1.HasValue ? new int?((int)nullable1.GetValueOrDefault()) : new int?();
            //    if (!(nullable2.HasValue ? new bool?(nullable2.GetValueOrDefault() == num) : new bool?()).GetValueOrDefault())
            //        return this.MATCHCONSTITUENTID.Value;
            //}

            DataFormSaveRequest request = new DataFormSaveRequest();

            try
            {
                DataFormSaveRequest dataFormSaveRequest = request;
                dataFormSaveRequest.FormID              = new Guid("4417055D-0EFD-4F02-AF00-EA24CD901E7E");
                dataFormSaveRequest.ID                  = this.DUPLICATERECORDID.Value.ToString();
                dataFormSaveRequest.SecurityContext     = this.GetRequestSecurityContext();
                dataFormSaveRequest.DataFormItem        = _customModel.GetSaveDataFormItem;
                dataFormSaveRequest.AggregateExceptions = true;
                ServiceMethods.DataFormSave(request, this.GetRequestContext());
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                string message = ex.Message;

                if (null != ex.InnerException)
                {
                    message += $" {ex.InnerException.Message}";
                }

                throw new InvalidUIModelException(message);
            }

            return(_customModel.MATCHCONSTITUENTID.Value);
        }
Esempio n. 2
0
        public Guid SaveConstituentInfo()
        {
            DataFormSaveRequest request = new DataFormSaveRequest();

            try
            {
                DataFormSaveRequest dataFormSaveRequest = request;
                dataFormSaveRequest.FormID              = new Guid("ca71fa3d-5cdd-4386-88d8-cc2a89604b43");
                dataFormSaveRequest.ID                  = erbBatchRowID.ToString();
                dataFormSaveRequest.SecurityContext     = this.GetRequestSecurityContext();
                dataFormSaveRequest.DataFormItem        = _customModel.GetSaveDataFormItem;
                dataFormSaveRequest.AggregateExceptions = true;
                ServiceMethods.DataFormSave(request, this.GetRequestContext());
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                throw new InvalidUIModelException(ex.Message);
            }
            return(_customModel.MATCHCONSTITUENTID.Value);
        }
        public override AppBusinessProcessResult StartBusinessProcess()
        {
            AppBusinessProcessResult result = new AppBusinessProcessResult()
            {
                NumberSuccessfullyProcessed = 0,
                NumberOfExceptions = 0
            };
            
            using (SqlConnection conn = this.RequestContext.OpenAppDBConnection(RequestContext.ConnectionContext.BusinessProcess))
            {
                this.UpdateProcessStatus("Retrieving list of active currencies...");
                Dictionary<string, Currency> currencies = (Dictionary<string, Currency>)LoadActiveCurrencies(conn);

                // There are no active currencies in CRM, therefore there is nothing to do
                if (currencies.Count == 0)
                {
                    return result;
                }

                // The Free Edition of Fixer only supports the Euro as the base currency. If the Euro is not present, there is nothing to do.
                if (!currencies.ContainsKey(EUR_SYMBOL))
                {
                    return result;
                }
                
                this.UpdateProcessStatus("Retrieving process properties...");
                LoadProperties(conn);

                // Initialize third party service
                _service = new Fixer.Service(_accessKey);

                this.UpdateProcessStatus("Retrieving list of currencies supported by the rate provider...");
                Dictionary<string, string> supportedCurrencies = (Dictionary<string, string>)_service.GetSupportedCurrencies().Symbols;

                // Remove currencies not supported by the rate provider
                foreach (var r in currencies.Where(c => !supportedCurrencies.ContainsKey(c.Key)).ToList())
                {
                    currencies.Remove(r.Key);
                }

                // There are no supported currencies in CRM, therefore there is nothing to do
                if (currencies.Count == 0)
                {
                    return result;
                }

                // Get exchange rates
                ExchangeRates rateResponse;
                this.UpdateProcessStatus("Retrieving currency exchange rates from the rate provider...");
                switch (_dateCode)
                {
                    case Common.DateCode.Latest:
                        rateResponse = _service.GetLatestRates(currencies.Keys.ToList<string>());
                        break;
                    case Common.DateCode.Historical:
                        rateResponse = _service.GetHistoricalRates(_date, currencies.Keys.ToList<string>());
                        break;
                    default:
                        throw new ServiceException("Invalid process date code encountered.");
                }

                // Prepare to add the rates
                Guid baseCurrencyId = currencies[rateResponse.Base].Id;
                DateTime date = rateResponse.Date.AddTicks(rateResponse.Timestamp);
                Guid timeZoneId = GetTimeZoneId(conn);

                // Add rates, except the one that goes from base to base. Fixer includes this in the output.
                foreach(var r in rateResponse.Rates.Where(r => currencies[r.Key].Id != baseCurrencyId))
                {
                    // Create request
                    DataFormSaveRequest request = new DataFormSaveRequest()
                    {
                        FormID = new Guid("9b16843e-c20a-4ddf-b31b-1d179380476e"), // CurrencyExchangeRate.Add.xml
                        SecurityContext = new RequestSecurityContext()
                        {
                            SecurityFeatureID = new Guid("37e7492f-9a86-4029-b125-d133f330bf90"), // ExchangeRateRefresh.BusinessProcess.xml
                            SecurityFeatureType = SecurityFeatureType.BusinessProcess
                        },
                        DataFormItem = new AppFx.XmlTypes.DataForms.DataFormItem()
                    };

                    // Fill out form
                    request.DataFormItem.SetValue("FROMCURRENCYID", baseCurrencyId);
                    request.DataFormItem.SetValue("TOCURRENCYID", currencies[r.Key].Id);
                    request.DataFormItem.SetValue("TYPECODE", 1); // Daily
                    request.DataFormItem.SetValue("RATE", r.Value);
                    request.DataFormItem.SetValue("ASOFDATETIME", date);
                    request.DataFormItem.SetValue("TIMEZONEENTRYID", timeZoneId);

                    // Save the form
                    try
                    {
                        ServiceMethods.DataFormSave(request, this.RequestContext);
                        result.NumberSuccessfullyProcessed++;
                    }
                    catch
                    {
                        result.NumberOfExceptions++;
                    }
                }
            }

            return result;
        }