Пример #1
0
        private static async Task ValidateFundInvestorAsync(this MasterSideLetterDataAccess dataAccess, FundInvestor fundInvestor)
        {
            if (!string.IsNullOrEmpty(fundInvestor.FundName))
            {
                var fund = await dataAccess.GetOrCreateFundAsync(
                    fundInvestor.FundName,
                    fundInvestor.FundSponsorName,
                    fundInvestor.FundBusinessUnitName,
                    fundInvestor.FundStrategyName,
                    fundInvestor.FundYear,
                    fundInvestor.FundSize
                    );

                var updated = false;
                if (fund.SponsorName != fundInvestor.FundSponsorName)
                {
                    updated = true;
                    var sponsor = await dataAccess.GetOrCreateSponsorAsync(fundInvestor.FundSponsorName);

                    fund.SponsorId   = sponsor.Id;
                    fund.SponsorName = sponsor.Name;
                }

                if (fund.BusinessUnitName != fundInvestor.FundBusinessUnitName)
                {
                    updated = true;
                    var businessUnit = await dataAccess.GetOrCreateBusinessUnitAsync(fundInvestor.FundBusinessUnitName);

                    fund.BusinessUnitId   = businessUnit.Id;
                    fund.BusinessUnitName = businessUnit.Name;
                }

                if (fund.StrategyName != fundInvestor.FundStrategyName)
                {
                    updated = true;
                    var strategy = await dataAccess.GetOrCreateStrategyAsync(fundInvestor.FundStrategyName);

                    fund.StrategyId   = strategy.Id;
                    fund.StrategyName = strategy.Name;
                }

                if (fund.Year != fundInvestor.FundYear)
                {
                    updated   = true;
                    fund.Year = fundInvestor.FundYear;
                }

                if (fund.Size != fundInvestor.FundSize)
                {
                    updated   = true;
                    fund.Size = fundInvestor.FundSize;
                }

                if (updated)
                {
                    await dataAccess.UpdateFundAsync(fund);
                }

                fundInvestor.FundId = fund.Id;
            }

            if (!string.IsNullOrEmpty(fundInvestor.InvestorName))
            {
                var investor = await dataAccess.GetOrCreateInvestorAsync(fundInvestor.InvestorName, fundInvestor.InvestorType);

                if (investor.InvestorType != fundInvestor.InvestorType)
                {
                    investor.InvestorType = fundInvestor.InvestorType;
                    await dataAccess.UpdateInvestorAsync(investor);
                }
                fundInvestor.InvestorId = investor.Id;
            }
        }