public static Location UpdateModel(this Location location, LocationEditModel locationEditModel) { if (locationEditModel != null) { var locationInfo = string.Concat(locationEditModel.Address1?.Trim(), locationEditModel.Address2?.Trim(), locationEditModel.City?.Trim(), locationEditModel.State?.Trim(), locationEditModel.PostalCode?.Trim(), locationEditModel.Name?.Trim(), locationEditModel.PhoneNumber?.Trim()); if (string.IsNullOrWhiteSpace(locationInfo)) { location = null; } else { if (location == null || locationEditModel.Id.GetValueOrDefault() != 0) { location = new Location(); } location.Address1 = locationEditModel.Address1; location.Address2 = locationEditModel.Address2; location.City = locationEditModel.City; location.Country = locationEditModel.Country; location.Name = locationEditModel.Name; location.PhoneNumber = locationEditModel.PhoneNumber; if (!string.IsNullOrWhiteSpace(locationEditModel.PostalCode)) { location.PostalCode = new PostalCodeGeo { PostalCode = locationEditModel.PostalCode, City = locationEditModel.City, State = locationEditModel.State }; } location.State = locationEditModel.State; return location; } } return location; }
public LocationViewModel(Location location) { Address1 = location.Address1; Address2 = location.Address2; City = location.City; State = location.State; PostalCode = location.PostalCode; Country = location.Country; }
protected override void LoadTestData() { var context = ServiceProvider.GetService<AllReadyContext>(); var seattlePostalCode = new PostalCodeGeo { City = "Seattle", PostalCode = "98117", State = "WA" }; var 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 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 Event { 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<EventSkill>() }; context.PostalCodes.Add(seattlePostalCode); context.Locations.Add(seattle); context.Organizations.Add(htb); context.Events.Add(queenAnne); context.SaveChanges(); }
public static Location ToModel(this LocationViewModel location) { var value = new Location { Address1 = location.Address1, Address2 = location.Address2, City = location.City, PostalCode = location.PostalCode, State = location.State, Country = "TODO: Put country in both objects" }; return value; }
public void SetLocationToNewLocationViewModelWithCorrectData_WhenEventsLocationIsNotNull_AndConstructingWithNonNullCampaignAndNonNullManagingOrganization() { var location = new Location { Address1 = "Address1", Address2 = "Address2", City = "City", State = "State", PostalCode = "PostalCode", Country = "Country" }; var @event = new Models.Event { Location = location }; var sut = new EventViewModel(@event); Assert.Equal(sut.Location.Address1, location.Address1); Assert.Equal(sut.Location.Address2, location.Address2); Assert.Equal(sut.Location.City, location.City); Assert.Equal(sut.Location.State, location.State); Assert.Equal(sut.Location.PostalCode, location.PostalCode); Assert.Equal(sut.Location.Country, location.Country); }
public async Task ExistingEventUpdateLocation() { var seattlePostalCode = "98117"; var 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>(); var 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>() }; var firePrev = new Campaign { Id = 1, Name = "Neighborhood Fire Prevention Days", ManagingOrganization = htb, TimeZoneId = "Central Standard Time" }; htb.Campaigns.Add(firePrev); var queenAnne = new Event { 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<EventSkill>() }; context.Locations.Add(seattle); context.Organizations.Add(htb); context.Events.Add(queenAnne); context.SaveChanges(); var NEW_LOCATION = LocationExtensions.ToEditModel(new Location { Address1 = "123 new address", Address2 = "new suite", PostalCode = "98004", City = "Bellevue", State = "WA", Country = "USA", Name = "New name", PhoneNumber = "New number" }); var locationEdit = new EventEditViewModel { 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, OrganizationId = queenAnne.Campaign.ManagingOrganizationId, OrganizationName = queenAnne.Campaign.ManagingOrganization.Name, }; var query = new EditEventCommand { Event = locationEdit }; var handler = new EditEventCommandHandler(context); var result = await handler.Handle(query); Assert.Equal(100, result); // should get back the event id var data = context.Events.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, 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); }
protected override void LoadTestData() { var seattlePostalCode = "98117"; var seattle = new Location { Address1 = "123 Main Street", Address2 = "Unit 2", City = "Seattle", PostalCode = seattlePostalCode, Country = "USA", State = "WA", Name = "Organizer name", PhoneNumber = "555-555-5555" }; var 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 Event { 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<EventSkill>(), EventType = EventType.Itinerary }; var rallyEvent = new Event { Name = "Queen Anne Fire Prevention Day Rally", 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<EventSkill>(), EventType = EventType.Rally }; var task1 = new AllReadyTask { Event = rallyEvent, Name = "Task1", IsLimitVolunteers = false, StartDateTime = new DateTime(2016, 7, 5, 10, 0, 0).ToUniversalTime(), EndDateTime = new DateTime(2016, 7, 5, 15, 0, 0).ToUniversalTime() }; var request1 = new Request { RequestId = Guid.NewGuid(), Name = "Request1", Status = RequestStatus.Assigned, Latitude = 50.768, Longitude = 0.2905 }; var request2 = new Request { RequestId = Guid.NewGuid(), Name = "Request2", Status = RequestStatus.Assigned, Latitude = 50.768, Longitude = 0.2905 }; var request3 = new Request { RequestId = Guid.NewGuid(), Name = "Request3", Status = RequestStatus.Assigned, Latitude = 50.768, Longitude = 0.2905 }; var itinerary1 = new Itinerary { Date = new DateTime(2015, 07, 5), Name = "Itinerary1", Event = queenAnne }; var itinerary2 = new Itinerary { Date = new DateTime(2016, 08, 01), Name = "Itinerary2", Event = queenAnne }; var itineraryReq1 = new ItineraryRequest { RequestId = request1.RequestId, Itinerary = itinerary1 }; var itineraryReq2 = new ItineraryRequest { RequestId = request2.RequestId, Itinerary = itinerary1 }; var itineraryReq3 = new ItineraryRequest { RequestId = request3.RequestId, Itinerary = itinerary2 }; var user1 = new ApplicationUser { Id = Guid.NewGuid().ToString(), UserName = "******" }; var taskSignup = new TaskSignup { Itinerary = itinerary1, Task = task1, }; Context.Locations.Add(seattle); Context.Requests.AddRange(request1, request2, request3); Context.Itineraries.AddRange(itinerary1, itinerary2); Context.ItineraryRequests.AddRange(itineraryReq1, itineraryReq2, itineraryReq3); Context.Organizations.Add(htb); Context.Events.Add(queenAnne); Context.Events.Add(rallyEvent); Context.Users.Add(user1); Context.Tasks.Add(task1); Context.TaskSignups.Add(taskSignup); Context.SaveChanges(); }