Ejemplo n.º 1
0
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService <AllReadyContext>();

            PostalCodeGeo seattlePostalCode = new PostalCodeGeo()
            {
                City = "Seattle", PostalCode = "98117", State = "WA"
            };
            Location seattle = new Location()
            {
                Id          = 1,
                Address1    = "123 Main Street",
                Address2    = "Unit 2",
                City        = "Seattle",
                PostalCode  = seattlePostalCode,
                Country     = "USA",
                State       = "WA",
                Name        = "Organizer name",
                PhoneNumber = "555-555-5555"
            };


            Organization 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>()
            };

            var firePrev = new Campaign
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb
            };

            htb.Campaigns.Add(firePrev);

            var 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>()
            };

            context.PostalCodes.Add(seattlePostalCode);
            context.Locations.Add(seattle);
            context.Organizations.Add(htb);
            context.Activities.Add(queenAnne);
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        public int Handle(OrganizationEditCommand message)
        {
            var organization = _context
                               .Organizations
                               .Include(l => l.Location).ThenInclude(p => p.PostalCode)
                               .Include(tc => tc.OrganizationContacts)
                               .SingleOrDefault(t => t.Id == message.Organization.Id);

            if (organization == null)
            {
                organization = new Organization();
            }

            organization.Name    = message.Organization.Name;
            organization.LogoUrl = message.Organization.LogoUrl;
            organization.WebUrl  = message.Organization.WebUrl;

            organization          = organization.UpdateOrganizationContact(message.Organization, _context);
            organization.Location = organization.Location.UpdateModel(message.Organization.Location);

            if (organization.Location != null)
            {
                if (!string.IsNullOrWhiteSpace(message.Organization.Location.PostalCode))
                {
                    PostalCodeGeo postalCode = _context.PostalCodes.SingleOrDefault(pc => pc.PostalCode.Equals(message.Organization.Location.PostalCode, System.StringComparison.InvariantCultureIgnoreCase));
                    if (postalCode == null)
                    {
                        postalCode = new PostalCodeGeo {
                            PostalCode = message.Organization.Location.PostalCode, City = message.Organization.Location.City, State = message.Organization.Location.State
                        };
                        _context.PostalCodes.Add(postalCode);
                    }
                    organization.Location.PostalCode = postalCode;
                }

                _context.Update(organization.Location);
            }

            organization.PrivacyPolicy = message.Organization.PrivacyPolicy;

            _context.Update(organization);
            _context.SaveChanges();

            return(organization.Id);
        }
        public void AddOrganizationWithKnownPostalCode()
        {
            // Arrange
            PostalCodeGeo m1T2T9 = OrganizationEditCommandHandlerTests.CreateM1T2T9();

            Context.PostalCodes.Add(m1T2T9);
            Context.SaveChanges();

            Organization          org      = CreateAgincourtAwareness();
            OrganizationEditModel orgModel = OrganizationEditCommandHandlerTests.ToEditModel_Organization(org);

            // Act
            OrganizationEditCommandHandler handler = new OrganizationEditCommandHandler(Context);
            int id = handler.Handle(new OrganizationEditCommand()
            {
                Organization = orgModel
            });
            Organization fetchedOrg = Context.Organizations.Where(t => t.Id == id).First();

            // Assert
            Assert.Single(Context.Organizations.Where(t => t.Id == id));
            Assert.NotEqual(fetchedOrg.Location.City, fetchedOrg.Location.PostalCode.City);
            Assert.NotEqual(fetchedOrg.Location.State, fetchedOrg.Location.PostalCode.State);
        }
Ejemplo n.º 4
0
        public void ExistingActivityUpdateLocation()
        {
            PostalCodeGeo seattlePostalCode = new PostalCodeGeo()
            {
                City = "Seattle", PostalCode = "98117", State = "WA"
            };
            Location seattle = new Location()
            {
                Id          = 1,
                Address1    = "123 Main Street",
                Address2    = "Unit 2",
                City        = "Seattle",
                PostalCode  = seattlePostalCode,
                Country     = "USA",
                State       = "WA",
                Name        = "Organizer name",
                PhoneNumber = "555-555-5555"
            };

            var          context = ServiceProvider.GetService <AllReadyContext>();
            Organization htb     = new Organization()
            {
                Id        = 123,
                Name      = "Humanitarian Toolbox",
                LogoUrl   = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl    = "http://www.htbox.org",
                Campaigns = new List <Campaign>()
            };
            Campaign firePrev = new Campaign()
            {
                Id   = 1,
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb,
                TimeZoneId           = "Central Standard Time"
            };

            htb.Campaigns.Add(firePrev);
            Activity queenAnne = new Activity()
            {
                Id             = 100,
                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       = seattle,
                RequiredSkills = new List <ActivitySkill>()
            };

            context.Locations.Add(seattle);
            context.Organizations.Add(htb);
            context.Activities.Add(queenAnne);
            context.SaveChanges();

            var NEW_LOCATION = LocationExtensions.ToEditModel(new Location()
            {
                Address1   = "123 new address",
                Address2   = "new suite",
                PostalCode = new PostalCodeGeo()
                {
                    City = "Bellevue", PostalCode = "98004", State = "WA"
                },
                City        = "Bellevue",
                State       = "WA",
                Country     = "USA",
                Name        = "New name",
                PhoneNumber = "New number"
            });

            var locationEdit = new ActivityDetailModel
            {
                CampaignId       = queenAnne.CampaignId,
                CampaignName     = queenAnne.Campaign.Name,
                Description      = queenAnne.Description,
                EndDateTime      = queenAnne.EndDateTime,
                Id               = queenAnne.Id,
                ImageUrl         = queenAnne.ImageUrl,
                Location         = NEW_LOCATION,
                Name             = queenAnne.Name,
                RequiredSkills   = queenAnne.RequiredSkills,
                TimeZoneId       = "Central Standard Time",
                StartDateTime    = queenAnne.StartDateTime,
                Tasks            = null,
                OrganizationId   = queenAnne.Campaign.ManagingOrganizationId,
                OrganizationName = queenAnne.Campaign.ManagingOrganization.Name,
                Volunteers       = null
            };

            var query = new EditActivityCommand {
                Activity = locationEdit
            };
            var handler = new EditActivityCommandHandler(context);
            var result  = handler.Handle(query);

            Assert.Equal(100, result); // should get back the activity id

            var data = context.Activities.Single(a => a.Id == result);

            Assert.Equal(data.Location.Address1, NEW_LOCATION.Address1);
            Assert.Equal(data.Location.Address2, NEW_LOCATION.Address2);
            Assert.Equal(data.Location.City, NEW_LOCATION.City);
            Assert.Equal(data.Location.PostalCode?.PostalCode, NEW_LOCATION.PostalCode);
            Assert.Equal(data.Location.State, NEW_LOCATION.State);
            Assert.Equal(data.Location.Country, NEW_LOCATION.Country);
            Assert.Equal(data.Location.PhoneNumber, NEW_LOCATION.PhoneNumber);
            Assert.Equal(data.Location.Name, NEW_LOCATION.Name);
        }