Beispiel #1
0
        public async Task AddAsync(BonusCashInDto bonusCashIn)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var historyEntity = TransactionHistoryEntity.Create(bonusCashIn);
                var bonusEntity   = BonusCashInEntity.Create(bonusCashIn);

                var campaign = await context.Campaigns.FindAsync(bonusCashIn.CampaignId);

                if (campaign != null && campaign.CampaignName != bonusCashIn.CampaignName)
                {
                    campaign.CampaignName = bonusCashIn.CampaignName;
                }

                if (campaign == null)
                {
                    campaign = CampaignEntity.Create(bonusCashIn.CampaignId, bonusCashIn.CampaignName);
                }

                bonusEntity.Campaign = campaign;

                context.BonusCashIns.Add(bonusEntity);
                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
        public async Task AddReferralStakeReleasedAsync(ReferralStakeDto referralStake)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var historyEntity = TransactionHistoryEntity.CreateForReferralStakeTokensRelease(referralStake);
                var releasedReferralStakeEntity = ReleasedReferralStakeEntity.Create(referralStake);

                var campaign = await context.Campaigns.FindAsync(referralStake.CampaignId);

                if (campaign != null && campaign.CampaignName != referralStake.CampaignName)
                {
                    campaign.CampaignName = referralStake.CampaignName;
                }

                if (campaign == null)
                {
                    campaign = CampaignEntity.Create(referralStake.CampaignId, referralStake.CampaignName);
                }

                releasedReferralStakeEntity.Campaign = campaign;

                context.ReleasedReferralStakes.Add(releasedReferralStakeEntity);
                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
        private async Task <CampaignEntity> GetAndUpdateCampaign(OperationsHistoryContext context, string campaignId, string campaignName)
        {
            var campaign = await context.Campaigns.FindAsync(campaignId);

            if (campaign != null && !string.IsNullOrEmpty(campaignName) && campaign.CampaignName != campaignName)
            {
                campaign.CampaignName = campaignName;
            }

            if (campaign == null)
            {
                campaign = CampaignEntity.Create(campaignId, campaignName);
            }

            return(campaign);
        }