示例#1
0
        public void Handle(ElectionMadeEvent args)
        {
            if (_mongoDataBase.CollectionExists("Elections") == false)
            {
                _mongoDataBase.CreateCollection("Elections");
            }

            //get the PlanId, PlanYear
            var planYearBenefitCollection = _mongoDataBase.GetCollection <PlanYearBenefitDto>("PlanYearBenefits");
            //var query = Query<PlanYearBenefitDto>.Where(pyb => pyb.Id == args.PlanYearBenefitId);
            var query           = Query.EQ("Id", args.PlanYearBenefitId);
            var planYearBenefit = planYearBenefitCollection.Find(query).FirstOrDefault();
            var planId          = planYearBenefit.PlanId;
            var planYear        = planYearBenefit.PlanYear;
            var benefitId       = planYearBenefit.BenefitId;

            //BenefitCode and BenefitType from other collections
            var benefitsCollection = _mongoDataBase.GetCollection <BenefitDto>("Benefits");
            //var benefitQuery = Query<BenefitDto>.Where(benefitDto => benefitDto.Id == benefitId);
            var benefitQuery = Query.EQ("Id", benefitId);
            var benefit      = benefitsCollection.Find(benefitQuery).FirstOrDefault();

            var electionCollection = _mongoDataBase.GetCollection <ElectionDto>("Elections");

            var electionDto = new ElectionDto
            {
                Id                  = args.Id,
                CompanyId           = args.CompanyCode,
                BenefitCode         = benefit.Id,
                BenefitType         = benefit.BenefitType,
                ElectionAmount      = args.ElectionAmount,
                Balance             = args.ElectionAmount,
                QualifyingEvent     = args.ElectionReason,
                ParticipantId       = args.ParticipantId,
                PerPayPeriodAmount  = args.PerPayPeriodAmount,
                IsTerminated        = false,
                PlanCode            = planId,
                PlanYear            = planYear,
                PlanYearBenefitId   = args.PlanYearBenefitId,
                PlanYearBenefitDesc = planYearBenefit.Name,
            };

            var safeModeResult = electionCollection.Save(electionDto);
            //use the safe mode result to test if the upsert was ok.
            //if the upsert failed, then we can generate a message (containing this event) and put it back on the bus
            //there could be an admin console that monitors this error q so that people know when upserts fail.
        }
示例#2
0
        public void DisburseClaim(DisburseClaim command, IElectionsReadModel electionsReadModel)
        {
            var         elections = electionsReadModel.GetElectionsForParticipant(command.ParticipantId);
            ElectionDto election  = null;

            if (TryGetElection(elections, _state.ClaimType, out election))
            {
                var electionBalance = electionsReadModel.GetElectionBalance(election.Id).BalanceRemaining;
                if (electionBalance - _state.ClaimAmount.Amount < 0)
                {
                    RaiseClaimNotDisbursedEvent(command,
                                                string.Format(
                                                    "Your remaining election balance is {0} which is not enough to cover your claim for {1}",
                                                    electionBalance, _state.ClaimAmount.Amount));
                    return;
                }
                RaiseClaimDisbursedEvent(command, election.Id);
            }
            else
            {
                RaiseClaimNotDisbursedEvent(command, string.Format("No election matches the claim type '{0}'", _state.ClaimType));
            }
        }
        private bool TryGetElection(IEnumerable<ElectionDto> elections, string claimTypeToFind, out ElectionDto election)
        {
            bool canFindClaimType = false;
            election = null;

            var electionFound = elections.FirstOrDefault(electionItem => claimTypeToFind.Contains(electionItem.BenefitType));
            if (electionFound != null)
            {
                canFindClaimType = true;
                election = electionFound;
            }

            return canFindClaimType;
        }
示例#4
0
        private bool TryGetElection(IEnumerable <ElectionDto> elections, string claimTypeToFind, out ElectionDto election)
        {
            bool canFindClaimType = false;

            election = null;

            var electionFound = elections.FirstOrDefault(electionItem => claimTypeToFind.Contains(electionItem.BenefitType));

            if (electionFound != null)
            {
                canFindClaimType = true;
                election         = electionFound;
            }

            return(canFindClaimType);
        }