public async Task <IEnumerable <GrmEventInformationDto> > GetOwnerGrmEvents(BaseValueSegmentDto baseValueSegmentDto)
        {
            // build search object
            var grmEventSearchDto = new GrmEventSearchDto();
            var idList            = new List <int>();

            var firstTransaction = baseValueSegmentDto.FirstTransaction();

            // get owner grm event ids
            var owners = firstTransaction.BaseValueSegmentOwners;

            // ReSharper disable once PossibleInvalidOperationException
            var grmEventIds = owners.Where(o => o.GRMEventId.HasValue).Select(owner => owner.GRMEventId.Value).Distinct();

            idList.AddRange(grmEventIds);

            // get header grm event ids
            var headerValuesGrmEventIds = firstTransaction.BaseValueSegmentValueHeaders.Where(hv => hv.GRMEventId.HasValue).Select(hv => hv.GRMEventId.Value).Distinct();

            idList.AddRange(headerValuesGrmEventIds);

            grmEventSearchDto.GrmEventIdList.AddRange(idList.Distinct());

            // call service with search object to get grm event associated to this base value segment
            var eventInformationDtos = _grmEventRepository.SearchAsync(grmEventSearchDto).Result;

            var effectiveDate   = baseValueSegmentDto.AsOf;
            var revenueObjectId = baseValueSegmentDto.RevenueObjectId;

            // call service with search object to get legal parties associated to this base value segment
            var grmEventInformationDtos = await _grmEventRepository.GetAsync(revenueObjectId, effectiveDate);

            // return unique set
            return(eventInformationDtos.Union(grmEventInformationDtos, new GrmEventInformationDtoComparer()).ToArray());
        }
        private async Task <BvsComponenDto> CreateReadBvsTransactionByComponents(DateTime assessmentEventDate, BaseValueSegmentDto baseValueSegmentDto, int assessmentEventType)
        {
            var bvsDto = new BvsComponenDto {
                Source = baseValueSegmentDto
            };

            // get the events defined for the this bvs based on the SubComponentand revenue object
            var events = (await _grmEventDomain.GetValueHeaderGrmEvents(baseValueSegmentDto)).ToList();
            var conclusionHeaderEvents = _baseValueSegmentRepository.GetConclusionsData(baseValueSegmentDto.RevenueObjectId, baseValueSegmentDto.AsOf).Result;

            foreach (var grmEvent in events)
            {
                var conclusionEvent = conclusionHeaderEvents.FirstOrDefault(conclusion => conclusion.GrmEventId == grmEvent.GrmEventId);
                if (conclusionEvent != null)
                {
                    grmEvent.EventType = conclusionEvent.Description;
                }
            }

            events.PopulateEvent(bvsDto);

            // take the first transaction for the bvs
            var firstTransaction = baseValueSegmentDto.FirstTransaction();

            bvsDto.Components = CreateComponents(firstTransaction, events, baseValueSegmentDto.AsOf, baseValueSegmentDto.RevenueObjectId, assessmentEventDate, assessmentEventType);

            bvsDto.ValueHeaders = GetBaseValueSegmentHeaderEvents(baseValueSegmentDto, firstTransaction);

            bvsDto.BaseValueSegmentTransactionTypeDescription = firstTransaction.BaseValueSegmentTransactionType.Description;

            // get the legal parties and document information associated to base value segment
            var legalPartyRoleDocuments = (await _legalPartyDomain.GetLegalPartyRoleDocuments(baseValueSegmentDto)).ToList();

            bvsDto.Owners = firstTransaction.BaseValueSegmentOwners.ToList().Select(bvsOwner =>
            {
                var doc = legalPartyRoleDocuments.First(d => d.LegalPartyRoleId == bvsOwner.LegalPartyRoleId);

                // We are only populating 3 fields for the sub components because only the 3 fields are used for
                // determing what's the base value, market values for each BI based on the ordering of these 3
                // fields. These values are used to reallocate base values/ market values if they are changed by
                // the user in the UI.
                return(new OwnerDto
                {
                    // We must have an Owner Id.
                    // ReSharper disable once PossibleInvalidOperationException
                    OwnerId = bvsOwner.Id.Value,
                    BeneficialInterest = doc.LegalPartyDisplayName,
                    BiPercentage = bvsOwner.BeneficialInterestPercent
                });
            }).ToArray();

            return(bvsDto);
        }
Esempio n. 3
0
        private async Task <BvsDetailDto> CreateReadBvsTransactionByDetails(DateTime assessmentEventDate, BaseValueSegmentDto baseValueSegmentDto)
        {
            var bvsDto = new BvsDetailDto {
                Source = baseValueSegmentDto
            };

            // get the legal parties and document information associated to base value segment
            var legalPartyRoleDocuments = (await _legalPartyDomain.GetLegalPartyRoleDocuments(baseValueSegmentDto)).ToList();

            // get the unique set of events defined for the this bvs and revenue object
            var events = (await _grmEventDomain.GetOwnerGrmEvents(baseValueSegmentDto)).ToList();

            events.PopulateEvent(bvsDto);

            // take the first transaction for the bvs
            bvsDto.Details = (await CreateDetails(baseValueSegmentDto.FirstTransaction(), events, legalPartyRoleDocuments, assessmentEventDate, baseValueSegmentDto.RevenueObjectId));

            return(bvsDto);
        }
        public void ShouldGetFirstTransactionOrderedByIdFromBaseValueSegmentWhereIdIsAtLast()
        {
            var dto = new BaseValueSegmentDto
            {
                BaseValueSegmentTransactions = new List <BaseValueSegmentTransactionDto>
                {
                    new BaseValueSegmentTransactionDto {
                        Id = 101
                    },
                    new BaseValueSegmentTransactionDto {
                        Id = 102
                    },
                    new BaseValueSegmentTransactionDto {
                        Id = 300
                    }
                }
            };
            var firstTransaction = dto.FirstTransaction();

            firstTransaction.Id.ShouldBe(300);
        }
        private async Task <BvsOwnerDto> CreateReadBvsTransactionByOwners(DateTime assessmentEventDate, BaseValueSegmentDto baseValueSegmentDto, int assessmentEventType)
        {
            var bvsDto = baseValueSegmentDto.ToBvsOwnerDto();

            // get the legal parties and document information associated to base value segment
            var legalPartyRoleDocuments = (await _legalPartyDomain.GetLegalPartyRoleDocuments(baseValueSegmentDto)).ToList();

            // get the unique set of events defined for the this bvs and revenue object
            var events = (await _grmEventDomain.GetOwnerGrmEvents(baseValueSegmentDto)).ToList();

            events.PopulateEvent(bvsDto);

            var firstTransaction = baseValueSegmentDto.FirstTransaction();

            // take the first transaction for the bvs
            bvsDto.Owners = await CreateOwners(firstTransaction, events, legalPartyRoleDocuments, assessmentEventDate, assessmentEventType);

            bvsDto.ValueHeaders = GetBaseValueSegmentHeaderEvents(baseValueSegmentDto, firstTransaction);

            bvsDto.BaseValueSegmentTransactionTypeDescription = firstTransaction.BaseValueSegmentTransactionType.Description;

            return(bvsDto);
        }