Beispiel #1
0
        public CampaignEditModel GetEditModel(long campaignId)
        {
            if (campaignId <= 0)
            {
                return(new CampaignEditModel());
            }

            var campaign                   = _campaignRepository.GetById(campaignId);
            var campaignActivities         = _campaignActivityRepository.GetByCampaignId(campaignId);
            var campaignAssignment         = _campaignAssignmentRepository.GetByCampaignId(campaignId);
            var campaignActivityAssignment = _campaignActivityAssignmentRepository.GetByCampaignId(campaignId);

            var model = CampaignDomainToModel(campaign);

            model.Assignments = GetCampaignAssignments(campaignId, campaignAssignment);

            if (campaignActivities != null && campaignActivities.Any())
            {
                var activityList = new List <CampaignActivityEditModel>();
                foreach (var activity in campaignActivities)
                {
                    var activityEditModel = CampaignActivityDomainToModel(activity);

                    var activityAssignments = campaignActivityAssignment.Where(x => x.CampaignActivityId == activity.Id);

                    activityEditModel.Assignments = GetActivityAssignment(activityAssignments, campaignActivityAssignment, activity);

                    activityList.Add(activityEditModel);

                    model.CampaignActivity = activityList;
                }
            }

            return(model);
        }
Beispiel #2
0
        private bool IsValidCampaignDate(UpdatePublishedCampaignEditModel model)
        {
            var activities = _campaignActivityRepository.GetByCampaignId(model.CampaignId);

            if (activities == null || !activities.Any())
            {
                return(false);
            }

            var result = true;

            if (model.CampaignStartDate.HasValue && model.CampaignEndDate.HasValue)
            {
                result = !activities.Any(x => x.ActivityDate < model.CampaignStartDate || x.ActivityDate > model.CampaignEndDate);
            }

            return(result);
        }
        public void PollForHealthPlanMailRoundCallQueue()
        {
            try
            {
                var callDate           = DateTime.Now;
                var campaigns          = new List <Campaign>();
                var campaignByCallDate = _campaignRepository.GeCotporateCampaignForCallQueue(callDate);

                if (!campaignByCallDate.IsNullOrEmpty())
                {
                    campaigns.AddRange(campaignByCallDate);
                }

                var campaignsNotGenerated = _campaignRepository.GetCotporateCampaignForNotGenerated();

                if (!campaignsNotGenerated.IsNullOrEmpty())
                {
                    var campaigIds = campaigns.Select(x => x.Id).ToArray();
                    if (!campaigIds.IsNullOrEmpty())
                    {
                        campaignsNotGenerated = campaignsNotGenerated.Where(x => !campaigIds.Contains(x.Id)).ToArray();
                        if (!campaignsNotGenerated.IsNullOrEmpty())
                        {
                            campaigns.AddRange(campaignsNotGenerated);
                        }
                    }
                    else
                    {
                        campaigns.AddRange(campaignsNotGenerated);
                    }
                }

                if (campaigns.IsNullOrEmpty())
                {
                    _logger.Info("No Campaigns found for call queue generation.");
                    return;
                }

                var healthPlanIds = campaigns.Select(x => x.AccountId).ToArray();
                var healthPlans   = _corporateAccountRepository.GetByIds(healthPlanIds);

                foreach (var campaign in campaigns)
                {
                    try
                    {
                        _logger.Info("Started creating Mail Round call queue for campaign: " + campaign.Name);

                        var campaignActivites = _campaignActivityRepository.GetByCampaignId(campaign.Id);

                        var outboundCallAcivity = campaignActivites.FirstOrDefault(ca => ca.TypeId == (long)CampaignActivityType.OutboundCall && ca.ActivityDate.Date == callDate.Date);

                        if (outboundCallAcivity == null)
                        {
                            outboundCallAcivity = campaignActivites.Where(ca => ca.TypeId == (long)CampaignActivityType.OutboundCall).OrderByDescending(x => x.ActivityDate).FirstOrDefault();
                        }

                        if (outboundCallAcivity == null)
                        {
                            continue;
                        }

                        var firstDirectMailActivity = campaignActivites.Where(ca => ca.TypeId == (long)CampaignActivityType.DirectMail && ca.ActivityDate <= outboundCallAcivity.ActivityDate).OrderBy(ca => ca.ActivityDate).FirstOrDefault();

                        if (firstDirectMailActivity == null)
                        {
                            _logger.Info("No Direct mail activity before outbound call.");
                            _logger.Info("Completed creating Mail Round call queue for campaign: " + campaign.Name);
                            continue;
                        }

                        var criterias = _healthPlanCallQueueCriteriaRepository.GetByCampaignId(campaign.Id);
                        if (criterias.IsNullOrEmpty())
                        {
                            _logger.Info("No Criteria has been created.");
                            _logger.Info("Completed creating Mail Round call queue for campaign: " + campaign.Name);
                            continue;
                        }

                        foreach (var campaingnCriteria in criterias)
                        {
                            try
                            {
                                if (campaingnCriteria.IsQueueGenerated && campaingnCriteria.LastQueueGeneratedDate.HasValue && campaingnCriteria.LastQueueGeneratedDate.Value.Date == callDate.Date)
                                {
                                    _logger.Info("Call queue has been already generated for the campaign.");
                                    _logger.Info("Completed creating Mail Round call queue for campaign: " + campaign.Name);
                                    continue;
                                }

                                _healthPlanCallQueueAssignmentRepository.DeleteByCriteriaId(campaingnCriteria.Id);

                                var healthPlan = healthPlans.Single(x => x.Id == campaign.AccountId);

                                var callQueue = _callQueueRepository.GetCallQueueByCategory(HealthPlanCallQueueCategory.MailRound);

                                _healthPlanCallRoundService.SaveMailRoundCallQueueCustomers(healthPlan, campaingnCriteria, callQueue, _logger, campaign);

                                campaingnCriteria.IsQueueGenerated       = true;
                                campaingnCriteria.LastQueueGeneratedDate = DateTime.Now;
                                _healthPlanCallQueueCriteriaRepository.Save(campaingnCriteria);
                            }
                            catch (Exception ex)
                            {
                                _logger.Error("Some Error Occurred While Generating Campaign Criteria Data: " + campaign.Name);
                                _logger.Error("Message: " + ex.Message);
                                _logger.Error("Stack Trace: " + ex.StackTrace);
                            }
                        }

                        _logger.Info("Completed creating Mail Round call queue for campaign: " + campaign.Name);
                    }
                    catch (Exception ex)
                    {
                        _logger.Error("Error while Creating Mail Round call queue for campaign: " + campaign.Name);
                        _logger.Error("Message : " + ex.Message);
                        _logger.Error("Stack Trace : " + ex.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error while Polling Mail Round call queue");
                _logger.Error("Message : " + ex.Message);
                _logger.Error("Stack Trace : " + ex.StackTrace);
            }
        }