private static CampaignSettingDTO ItemToDTO(CampaignSetting CampaignSetting) =>
 new CampaignSettingDTO
 {
     Id      = CampaignSetting.Id,
     WorldId = CampaignSetting.WorldId,
     Name    = CampaignSetting.Name
 };
Ejemplo n.º 2
0
        private async Task CheckCampaignSubscription()
        {
            CampaignDataController objController   = new CampaignDataController();
            CampaignSetting        campaignSetting = await objController.GetCampaignSetting();

            if (!campaignSetting.IsSubscribed)
            {
                CampaignDataController controller = new CampaignDataController();
                await controller.SubscribeService(HostUrl, GetUsername);
            }
        }
        public async Task <ActionResult <CampaignSetting> > PostCampaignSetting(CampaignSettingDTO CampaignSettingDTO)
        {
            var CampaignSetting = new CampaignSetting
            {
                Name    = CampaignSettingDTO.Name,
                WorldId = CampaignSettingDTO.WorldId
            };

            _context.CampaignSetting.Add(CampaignSetting);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCampaignSetting), new { id = CampaignSetting.Id }, ItemToDTO(CampaignSetting)));
        }
        private List <Contact> GetCampaignContacts(CampaignSetting campaignSetting)
        {
            // create the query of contacts that matches campaign contact and is still subscribed
            IQueryable <Contact> contactsQuery = from c in _automailerContext.Contacts
                                                 join e in _automailerContext.CampaignContacts
                                                 on c.ContactId equals e.ContactId
                                                 where c.Unsubscribe == false &&
                                                 e.CampaignId == campaignSetting.CampaignId
                                                 select c;

            // the final list of contacts that will be receiving emails for this campaign
            return(contactsQuery.ToList());
        }
        public static void SeedTestData(ModelBuilder modelBuilder)
        {
            Campaign               testCampaign         = Campaign.Create("TEST", "A test campaign");
            List <Contact>         testContacts         = CreateContacts();
            List <CampaignContact> testCampaignContacts = CreateCampaignContacts(testCampaign, testContacts);
            EmailTemplate          emailTemplate        = EmailTemplate.Create(testFrom, testSubject, testContent);
            CampaignSetting        campaignSetting      = CampaignSetting.Create(testCampaign.CampaignId, emailTemplate.EmailTemplateId, 1);

            campaignSetting.Active = true; // newly created campaign settings are set to inactive by default

            modelBuilder.Entity <Campaign>().HasData(testCampaign);
            modelBuilder.Entity <Contact>().HasData(testContacts);
            modelBuilder.Entity <CampaignContact>().HasData(testCampaignContacts);
            modelBuilder.Entity <EmailTemplate>().HasData(emailTemplate);
            modelBuilder.Entity <CampaignSetting>().HasData(campaignSetting);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> CreateCampaignSettings(Guid campaignId, Guid templateId, int emailDay)
        {
            try
            {
                CampaignSetting campaignSetting = CampaignSetting.Create(campaignId, templateId, emailDay);

                _automailerContext.CampaignSettings.Add(campaignSetting);
                await _automailerContext.SaveChangesAsync();

                return(Ok(campaignSetting));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(Problem(ex.Message));
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> ActivateCampaign(Guid id, bool active)
        {
            try
            {
                CampaignSetting campaignSetting = _automailerContext.CampaignSettings.FirstOrDefault(x => x.CampaignSettingId == id);
                if (campaignSetting == null)
                {
                    return(NotFound(id));
                }
                campaignSetting.Active = active;
                _automailerContext.CampaignSettings.Update(campaignSetting);
                await _automailerContext.SaveChangesAsync();

                return(Ok(campaignSetting));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(Problem(ex.Message));
            }
        }
        private CampaignTrackingModel CreateAutomailerTrackingModels(CampaignSetting campaignSetting)
        {
            EmailTemplate  emailTemplate = _automailerContext.EmailTemplates.FirstOrDefault(x => x.EmailTemplateId == campaignSetting.EmailTemplateId);
            List <Contact> contacts      = GetCampaignContacts(campaignSetting);

            List <AutomailerModel>  automailerModels  = new List <AutomailerModel>();
            List <CampaignTracking> campaignTrackings = new List <CampaignTracking>();

            foreach (Contact contact in contacts)
            {
                CampaignTracking campaignTracking = CampaignTracking.Create(campaignSetting.CampaignSettingId, emailTemplate.EmailTemplateId, contact.ContactId);
                campaignTrackings.Add(campaignTracking);

                AutomailerModel automailerModel = AutomailerModel.Create(ServerPath, campaignTracking.CampaignTrackingId, contact.ContactId, contact.Email, emailTemplate.EmailSubject, emailTemplate.EmailContent, contact.Name);
                automailerModels.Add(automailerModel);
            }

            return(new CampaignTrackingModel
            {
                AutomailerModels = automailerModels,
                CampaignTrackings = campaignTrackings
            });
        }
Ejemplo n.º 9
0
 CampaignSetting IBasicOperation <CampaignSetting> .Update(CampaignSetting entity)
 {
     throw new NotImplementedException();
 }