private async Task ProcessCampaignForCustomerAsync(MAVN.Service.BonusEngine.Domain.Models.Campaign campaign, CampaignCompletion campaignCompletion, Guid operationId, IReadOnlyDictionary <string, string> data) { var customerId = campaignCompletion.CustomerId; var campaignId = campaign.Id; var conditionCompletions = await _conditionCompletionService .GetConditionCompletionsAsync(customerId, campaignId); if (IsCampaignCompleted(conditionCompletions, campaign) == false) { return; } var reward = await _bonusCalculatorService.CalculateRewardAmountAsync(campaign, customerId, conditionCompletions); var bonusOperation = new BonusOperation { CustomerId = customerId, CampaignId = campaignId, ExternalOperationId = operationId, Reward = reward, TimeStamp = DateTime.UtcNow, BonusOperationType = BonusOperationType.CampaignReward }; if (data.TryGetValue(ReferralId, out string referralId)) { bonusOperation.ReferralId = referralId; } await _bonusOperationService.AddBonusOperationAsync(bonusOperation); _log.Info("Customer completed all condition in campaign.", context: $"operationId: {operationId}; campaignId: {campaignId}; customerId: {customerId}"); await _campaignCompletionService.IncreaseCompletionCountAsync(campaignCompletion, campaign, conditionCompletions); }
public async Task <CampaignCompletionModel> GetCampaignCompletionsByCustomerIdAsync(string customerId, string campaignId) { if (!Guid.TryParse(customerId, out _) || !Guid.TryParse(campaignId, out _)) { return(null); } var campaignCompletion = await _campaignCompletionService.GetByCampaignAsync(campaignId, customerId); var conditionCompletions = await _conditionCompletionService.GetConditionCompletionsAsync(customerId, campaignId); if (campaignCompletion == null) { return(null); } var model = _mapper.Map <CampaignCompletionModel>(campaignCompletion); model.ConditionCompletions = _mapper.Map <IReadOnlyList <ConditionCompletionModel> >(conditionCompletions); return(model); }