Exemplo n.º 1
0
        public static async Task<Organization> UpdateOrganizationContact(this Organization organization, IPrimaryContactViewModel contactModel, AllReadyContext _context)
        {
            if (organization.OrganizationContacts == null)
            {
                organization.OrganizationContacts = new List<OrganizationContact>();
            }

            var primaryCampaignContact = organization.OrganizationContacts.SingleOrDefault(tc => tc.ContactType == (int)ContactTypes.Primary);
            var contactId = primaryCampaignContact?.ContactId;
            Contact primaryContact;

            var contactInfo = string.Concat(contactModel.PrimaryContactEmail?.Trim() + contactModel.PrimaryContactFirstName?.Trim(), contactModel.PrimaryContactLastName?.Trim(), contactModel.PrimaryContactPhoneNumber?.Trim());
            if (contactId == null)
            {
                primaryContact = new Contact();
            }
            else
            {
                primaryContact = await _context.Contacts.SingleAsync(c => c.Id == contactId);
            }

            if (string.IsNullOrWhiteSpace(contactInfo) && primaryCampaignContact != null)
            {
                //Delete
                _context.OrganizationContacts.Remove(primaryCampaignContact);
                _context.Remove(primaryCampaignContact);//Not Needed?
                _context.Remove(primaryCampaignContact.Contact);
            }
            else
            {
                primaryContact.Email = contactModel.PrimaryContactEmail;
                primaryContact.FirstName = contactModel.PrimaryContactFirstName;
                primaryContact.LastName = contactModel.PrimaryContactLastName;
                primaryContact.PhoneNumber = contactModel.PrimaryContactPhoneNumber;
                _context.AddOrUpdate(primaryContact);

                if (primaryCampaignContact == null)
                {
                    primaryCampaignContact = new OrganizationContact
                    {
                        Contact = primaryContact,
                        Organization = organization,
                        ContactType = (int)ContactTypes.Primary
                    };
                    organization.OrganizationContacts.Add(primaryCampaignContact);
                    _context.AddOrUpdate(primaryCampaignContact);
                }
            }

            return organization;
        }
Exemplo n.º 2
0
        public static Campaign UpdateCampaignContact(this Campaign campaign, IPrimaryContactModel contactModel, AllReadyContext _context)
        {
            if (campaign.CampaignContacts == null)
            {
                campaign.CampaignContacts = new List<CampaignContact>();
            }

            var primaryCampaignContact = campaign.CampaignContacts.SingleOrDefault(tc => tc.ContactType == (int)ContactTypes.Primary);
            var contactId = primaryCampaignContact?.ContactId;
            Contact primaryContact;

            var contactInfo = string.Concat(contactModel.PrimaryContactEmail?.Trim() + contactModel.PrimaryContactFirstName?.Trim(), contactModel.PrimaryContactLastName?.Trim(), contactModel.PrimaryContactPhoneNumber?.Trim());

            if (contactId == null)
            {
                primaryContact = new Contact();
            }
            else
            {
                primaryContact = _context.Contacts.Single(c => c.Id == contactId);
            }

            if (string.IsNullOrWhiteSpace(contactInfo) && primaryCampaignContact != null)
            {
                //Delete
                _context.CampaignContacts.Remove(primaryCampaignContact);
                _context.Remove(primaryCampaignContact);//Not Needed?
                _context.Remove(primaryCampaignContact.Contact);
            }
            else
            {
                primaryContact.Email = contactModel.PrimaryContactEmail;
                primaryContact.FirstName = contactModel.PrimaryContactFirstName;
                primaryContact.LastName = contactModel.PrimaryContactLastName;
                primaryContact.PhoneNumber = contactModel.PrimaryContactPhoneNumber;
                _context.Update(primaryContact);

                if (primaryCampaignContact == null)
                {
                    primaryCampaignContact = new CampaignContact
                    {
                        Contact = primaryContact,
                        Campaign = campaign,
                        ContactType = (int)ContactTypes.Primary
                    };
                    campaign.CampaignContacts.Add(primaryCampaignContact);
                    _context.Update(primaryCampaignContact);
                }
            }
            return campaign;
        }
        public static void LoadCampaignssHandlerTestData(AllReadyContext context)
        {
            // Organizations
            context.Organizations.Add(new Organization { Id = 1, Name = "Org 1" });
            context.Organizations.Add(new Organization { Id = 2, Name = "Org 2" });

            // Campaigns
            context.Campaigns.Add(new Campaign { Name = "Campaign 1", ManagingOrganizationId = 1 });
            context.Campaigns.Add(new Campaign { Name = "Campaign 2", ManagingOrganizationId = 1 });
            context.Campaigns.Add(new Campaign { Name = "Locked Campaign", ManagingOrganizationId = 1, Locked = true });
            context.Campaigns.Add(new Campaign { Name = "Unlocked Campaign", ManagingOrganizationId = 1, Locked = false });

            // Contacts

            var newContact = new Contact { Email = "*****@*****.**", FirstName = "Bill", LastName = "Gates", PhoneNumber = "01323 000000" };
            context.Contacts.Add(newContact);
            context.CampaignContacts.Add(new CampaignContact { CampaignId = 1, ContactId = newContact.Id });
            
            // Geo
            context.PostalCodes.Add(new PostalCodeGeo { City = "Cincinnati", PostalCode = "45231", State = "OH" });

            context.SaveChanges();
        }
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService<AllReadyContext>();
            _user1 = new ApplicationUser
            {
                UserName = "******",
                Name = "John Doe",
                Email = "*****@*****.**"
            };
            _contact1 = new Contact
            {
                Id = 1,
                FirstName = "Jerry",
                LastName = "Rodgers",
                Email = "*****@*****.**",
                PhoneNumber = "555.555.1234"
            };

            _htb = new Organization()
            {
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };

            _firePrev = new Campaign()
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = _htb,
                CampaignContacts = new List<CampaignContact>()
            };
            _firePrev.CampaignContacts.Add(new CampaignContact
            {
                Campaign = _firePrev,
                Contact = _contact1,
                ContactType = (int)ContactTypes.Primary
            });
            _htb.Campaigns.Add(_firePrev);
            _queenAnne = new Activity()
            {
                Id = 1,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = _firePrev,
                CampaignId = _firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<ActivitySkill>(),
                Tasks = new List<AllReadyTask>()
            };
            _queenAnne.UsersSignedUp = new List<ActivitySignup>
            {
                new ActivitySignup
                {
                    Id = 1,
                    PreferredEmail = "*****@*****.**",
                    PreferredPhoneNumber = "(555)555-1234",
                    User = _user1
                }
            };
            _task1 = new AllReadyTask()
            {
               Id = 1,
               Activity = _queenAnne,
               Name = "Task 1",
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Organization = _htb
            };
            _task1.AssignedVolunteers = new List<TaskSignup>()
            {
                new TaskSignup
                {
                    Id = 1,
                    User = _user1,
                    Task = _task1,
                    Status = "Assigned",
                    StatusDateTimeUtc = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime()
                }
            };
            _queenAnne.Tasks.Add(_task1);
            context.Users.Add(_user1);
            context.Contacts.Add(_contact1);
            context.Organizations.Add(_htb);
            context.Activities.Add(_queenAnne);
            context.SaveChanges();
        }