public async Task InsertAsync(PropertyPurchase propertyPurchase)
        {
            using (var context = _msSqlContextFactory.CreateDataContext())
            {
                await context.AddAsync(_mapper.Map<PropertyPurchaseEntity>(propertyPurchase));

                await context.SaveChangesAsync();
            }
        }
Exemple #2
0
        public PropertyPurchaseServiceTestsFixture()
        {
            ReferralLeadRepositoryMock    = new Mock <IReferralLeadRepository>(MockBehavior.Strict);
            PropertyPurchaseRepositorMock = new Mock <IPropertyPurchaseRepository>(MockBehavior.Strict);
            StakeServiceMock = new Mock <IStakeService>(MockBehavior.Strict);

            Service = new PropertyPurchaseService(
                ReferralLeadRepositoryMock.Object,
                PropertyPurchaseRepositorMock.Object,
                StakeServiceMock.Object,
                new CommissionManager(MapperHelper.CreateAutoMapper()));

            ReferralLead = new ReferralLeadEncrypted
            {
                Id                = Guid.NewGuid(),
                AgentId           = AgentId,
                PhoneNumberHash   = PhoneNumber,
                EmailHash         = Email,
                ConfirmationToken = ConfirmationToken,
                CampaignId        = Guid.NewGuid()
            };

            ReferralLeadWithDetails = new ReferralLeadEncryptedWithDetails
            {
                Id                = Guid.NewGuid(),
                AgentId           = AgentId,
                PhoneNumberHash   = PhoneNumber,
                EmailHash         = Email,
                ConfirmationToken = ConfirmationToken
            };

            PropertyPurchase = new PropertyPurchase
            {
                Id             = Guid.NewGuid(),
                ReferralLeadId = Guid.NewGuid(),
                Timestamp      = DateTime.UtcNow
            };

            ReferralLeads = new List <ReferralLeadEncrypted> {
                ReferralLead
            };

            ReferralLeadsWithDetails = new List <ReferralLeadEncryptedWithDetails> {
                ReferralLeadWithDetails
            };

            PropertyPurchases = new List <PropertyPurchase>
            {
                PropertyPurchase,
                PropertyPurchase,
                PropertyPurchase
            };

            SetupCalls();
        }
Exemple #3
0
        private async Task PublishCommissionEvents(ReferralLead createdReferralLead)
        {
            var propertyPurchase = new PropertyPurchase
            {
                CurrencyCode         = "AED",
                DiscountAmount       = 1,
                NetPropertyPrice     = 1,
                ReferralLeadId       = createdReferralLead.Id,
                SellingPropertyPrice = 1,
                Timestamp            = DateTime.UtcNow,
                VatAmount            = 1
            };

            await _propertyPurchaseRepository.InsertAsync(propertyPurchase);

            var lead = await _referralLeadRepository.GetAsync(propertyPurchase.ReferralLeadId);
        }
        public T ToCommissionEvent <T>(PropertyPurchase propertyPurchase, ReferralLeadEncrypted lead)
            where T : PropertyPurchaseReferralEvent
        {
            var propertyPurchaseEvent = new PropertyPurchaseReferralEvent
            {
                ReferrerId                 = lead.AgentId.ToString(),
                TimeStamp                  = propertyPurchase.Timestamp,
                CurrencyCode               = propertyPurchase.CurrencyCode,
                VatAmount                  = propertyPurchase.VatAmount,
                DiscountAmount             = propertyPurchase.DiscountAmount,
                NetPropertyPrice           = propertyPurchase.NetPropertyPrice,
                SellingPropertyPrice       = propertyPurchase.SellingPropertyPrice,
                CalculatedCommissionAmount = propertyPurchase.CalculatedCommissionAmount,
                ReferralId                 = lead.Id.ToString()
            };

            return(_mapper.Map <T>(propertyPurchaseEvent));
        }
        public async Task <Guid> AddRealEstatePurchase(PropertyPurchase propertyPurchase)
        {
            var lead = await _referralLeadRepository.GetAsync(propertyPurchase.ReferralLeadId);

            if (lead == null)
            {
                throw new ReferralDoesNotExistException($"Referral lead with id '{propertyPurchase.ReferralLeadId} does not exist.'");
            }

            // If duplicate comes we want to skip releasing stake and inserting new entity
            if (!await _propertyPurchaseRepository.PropertyPurchaseExistsAsync(propertyPurchase.ReferralLeadId))
            {
                await _propertyPurchaseRepository.InsertAsync(propertyPurchase);

                if (lead.StakeEnabled)
                {
                    await _stakeService.ReleaseStake(lead.Id.ToString("D"), lead.CampaignId.Value, EstatePurchaseConditionName);
                }
            }

            return(lead.CampaignId.Value);
        }