Example #1
0
 public TaskViewModel(AllReadyTask task, bool isUserSignedupForTask)
     : this(task)
 {
     IsUserSignedUpForTask = isUserSignedupForTask;
 }
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService <AllReadyContext>();

            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 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>(),
                EventType      = EventType.Itinerary
            };

            var rallyEvent = new Event
            {
                Id            = 2,
                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      = new Location {
                    Id = 1
                },
                RequiredSkills = new List <EventSkill>(),
                EventType      = EventType.Rally
            };

            var task1 = new AllReadyTask
            {
                Id                = 1,
                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",
                Id      = 1,
                Event   = queenAnne,
                EventId = 1
            };

            var itinerary2 = new Itinerary
            {
                Date    = new DateTime(2016, 08, 01),
                Name    = "Itinerary2",
                Id      = 2,
                Event   = queenAnne,
                EventId = 1
            };

            var itineraryReq1 = new ItineraryRequest
            {
                RequestId   = request1.RequestId,
                ItineraryId = 1
            };

            var itineraryReq2 = new ItineraryRequest
            {
                RequestId   = request2.RequestId,
                ItineraryId = 1
            };

            var itineraryReq3 = new ItineraryRequest
            {
                RequestId   = request3.RequestId,
                ItineraryId = 2
            };

            var user1 = new ApplicationUser
            {
                Id       = Guid.NewGuid().ToString(),
                UserName = "******"
            };

            var taskSignup = new TaskSignup
            {
                ItineraryId = 1,
                Itinerary   = itinerary1,
                Task        = task1,
            };

            context.Requests.AddRange(request1, request2, request3);
            context.Itineraries.AddRange(itinerary1, itinerary2);
            context.ItineraryRequests.AddRange(itineraryReq1, itineraryReq2, itineraryReq3);
            context.Locations.Add(seattle);
            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();
        }
Example #3
0
        public TaskViewModel(AllReadyTask task, string userId = null)
        {
            Id          = task.Id;
            Name        = task.Name;
            Description = task.Description;

            if (task.StartDateTime.HasValue)
            {
                var startDateWithUtcKind = DateTime.SpecifyKind(DateTime.Parse(task.StartDateTime.Value.ToString()), DateTimeKind.Utc);
                StartDateTime = new DateTimeOffset(startDateWithUtcKind);
            }

            if (task.EndDateTime.HasValue)
            {
                var endDateWithUtcKind = DateTime.SpecifyKind(DateTime.Parse(task.EndDateTime.Value.ToString()), DateTimeKind.Utc);
                EndDateTime = new DateTimeOffset(endDateWithUtcKind);
            }

            if (task.Activity != null)
            {
                ActivityId   = task.Activity.Id;
                ActivityName = task.Activity.Name;
            }

            if (task.Activity?.Campaign != null)
            {
                CampaignId   = task.Activity.Campaign.Id;
                CampaignName = task.Activity.Campaign.Name;
            }

            if (task.Organization != null)
            {
                OrganizationId   = task.Organization.Id;
                OrganizationName = task.Organization.Name;
            }

            IsUserSignedUpForTask = false;
            if (task.AssignedVolunteers != null)
            {
                if (!string.IsNullOrWhiteSpace(userId))
                {
                    IsUserSignedUpForTask = task.AssignedVolunteers.Any(au => au.User.Id == userId);
                }

                AssignedVolunteers = new List <TaskSignupViewModel>();

                if (IsUserSignedUpForTask)
                {
                    foreach (var t in task.AssignedVolunteers.Where(au => au.User.Id == userId))
                    {
                        AssignedVolunteers.Add(new TaskSignupViewModel(t));
                    }
                }
            }

            if (task.RequiredSkills != null)
            {
                RequiredSkills       = task.RequiredSkills.Select(t => t.SkillId);
                RequiredSkillObjects = task.RequiredSkills?.Select(t => t.Skill).ToList();
            }

            NumberOfVolunteersRequired = task.NumberOfVolunteersRequired;
            NumberOfUsersSignedUp      = task.NumberOfUsersSignedUp;
            IsLimitVolunteers          = task.IsLimitVolunteers;
            IsAllowWaitList            = task.IsAllowWaitList;
        }
        public async Task UpdateExistingTaskSuccessfully()
        {
            var @event = new Event {
                Id = 3
            };
            var organization = new Organization {
                Id = 4
            };
            var task = new AllReadyTask
            {
                Id            = 2,
                Name          = "TaskName",
                Description   = "TaskDescription",
                Event         = @event,
                Organization  = organization,
                StartDateTime = DateTimeOffset.Now,
                EndDateTime   = DateTimeOffset.Now,
                NumberOfVolunteersRequired = 5,
                RequiredSkills             = new List <TaskSkill> {
                    new TaskSkill {
                        SkillId = 5, Skill = new Skill {
                            Id = 5, Name = "SkillName", Description = "SkillDescription"
                        }
                    }
                }
            };

            Context.Database.EnsureDeleted();
            Context.Events.Add(@event);
            Context.Organizations.Add(organization);
            Context.Tasks.Add(task);
            Context.SaveChanges();

            var message = new EditTaskCommandAsync
            {
                Task = new EditViewModel
                {
                    Id                         = task.Id,
                    Name                       = "TaskNameUpdated",
                    Description                = "TaskDescriptionUpdated",
                    EventId                    = @event.Id,
                    OrganizationId             = organization.Id,
                    TimeZoneId                 = "Central Standard Time",
                    StartDateTime              = DateTimeOffset.Now.AddDays(1),
                    EndDateTime                = DateTimeOffset.Now.AddDays(2),
                    NumberOfVolunteersRequired = 6,
                    RequiredSkills             = new List <TaskSkill> {
                        new TaskSkill {
                            SkillId = 6, Skill = new Skill {
                                Id = 6, Name = "SkillNameOnMessage", Description = "SkillDescriptionOnMessage"
                            }
                        }
                    }
                }
            };

            var sut    = new EditTaskCommandHandlerAsync(Context);
            var taskId = await sut.Handle(message);

            var result = Context.Tasks.Single(x => x.Id == taskId);

            //can't test start and end date as they're tied to static classes
            Assert.Equal(taskId, message.Task.Id);
            Assert.Equal(result.Name, message.Task.Name);
            Assert.Equal(result.Description, message.Task.Description);
            Assert.Equal(result.Event, @event);
            Assert.Equal(result.Organization, organization);
            Assert.Equal(result.NumberOfVolunteersRequired, message.Task.NumberOfVolunteersRequired);
            Assert.Equal(result.IsLimitVolunteers, @event.IsLimitVolunteers);
            Assert.Equal(result.IsAllowWaitList, @event.IsAllowWaitList);
            Assert.Equal(result.RequiredSkills, message.Task.RequiredSkills);
        }
Example #5
0
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService <AllReadyContext>();
            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
            };

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

            var username1 = $"*****@*****.**";
            var username2 = $"*****@*****.**";

            var user1 = new ApplicationUser {
                UserName = username1, Email = username1, EmailConfirmed = true
            };

            context.Users.Add(user1);
            var user2 = new ApplicationUser {
                UserName = username2, Email = username2, EmailConfirmed = true
            };

            context.Users.Add(user2);

            htb.Campaigns.Add(firePrev);
            context.Organizations.Add(htb);

            var task = new AllReadyTask
            {
                Event         = queenAnne,
                Description   = "Description of a very important task",
                Name          = "Task # ",
                EndDateTime   = DateTime.Now.AddDays(1),
                StartDateTime = DateTime.Now.AddDays(-3)
            };

            queenAnne.Tasks.Add(task);
            context.Events.Add(queenAnne);

            var taskSignups = new List <TaskSignup>
            {
                new TaskSignup {
                    Task = task, User = user1
                },
                new TaskSignup {
                    Task = task, User = user2
                }
            };

            context.TaskSignups.AddRange(taskSignups);

            context.SaveChanges();
        }
        protected override void LoadTestData()
        {
            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
            };

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

            var username1 = $"*****@*****.**";
            var username2 = $"*****@*****.**";

            var user1 = new ApplicationUser {
                UserName = username1, Email = username1, EmailConfirmed = true
            };

            Context.Users.Add(user1);
            var user2 = new ApplicationUser {
                UserName = username2, Email = username2, EmailConfirmed = true
            };

            Context.Users.Add(user2);

            var task = new AllReadyTask
            {
                Id    = 1,
                Name  = "Task 1",
                Event = queenAnne,
            };

            var taskSignup = new TaskSignup
            {
                Id   = 1,
                User = user1,
                Task = task
            };

            htb.Campaigns.Add(firePrev);
            Context.Organizations.Add(htb);
            Context.Events.Add(queenAnne);
            Context.Tasks.Add(task);
            Context.TaskSignups.Add(taskSignup);

            Context.SaveChanges();
        }
Example #7
0
        public static async Task <List <TaskSignup> > ToTaskSignups(this List <ViewModels.Event.TaskSignupViewModel> viewModels, AllReadyTask task, IMediator mediator)
        {
            var taskSignups = new List <TaskSignup>();

            foreach (var viewModel in viewModels)
            {
                taskSignups.Add(new TaskSignup
                {
                    Task = task,
                    User = await mediator.SendAsync(new UserByUserIdQuery {
                        UserId = viewModel.UserId
                    })
                });
            }

            return(taskSignups);
        }
        public async Task Handle(VolunteerSignupNotification notification)
        {
            // don't let problem with notification keep us from continuing
            try
            {
                var volunteer = await _context.Users.SingleAsync(u => u.Id == notification.UserId).ConfigureAwait(false);

                var campaignEvent = await _context.Events
                                    .Include(a => a.RequiredSkills).ThenInclude(r => r.Skill)
                                    .SingleAsync(a => a.Id == notification.EventId).ConfigureAwait(false);

                var eventSignup = campaignEvent.UsersSignedUp.FirstOrDefault(a => a.User.Id == notification.UserId);

                var campaign = await _context.Campaigns
                               .Include(c => c.CampaignContacts).ThenInclude(cc => cc.Contact)
                               .SingleOrDefaultAsync(c => c.Id == campaignEvent.CampaignId).ConfigureAwait(false);

                var campaignContact = campaign.CampaignContacts?.SingleOrDefault(tc => tc.ContactType == (int)ContactTypes.Primary);
                var adminEmail      = campaignContact?.Contact.Email;
                if (string.IsNullOrWhiteSpace(adminEmail))
                {
                    return;
                }

                var IsEventSignup = (campaignEvent.EventType == EventTypes.EventManaged);
                var eventLink     = $"View event: http://{_options.Value.SiteBaseUrl}/Admin/Event/Details/{campaignEvent.Id}";

                AllReadyTask task       = null;
                string       taskLink   = null;
                TaskSignup   taskSignup = null;

                if (!IsEventSignup)
                {
                    task = await _context.Tasks.SingleOrDefaultAsync(t => t.Id == notification.TaskId).ConfigureAwait(false);

                    if (task == null)
                    {
                        return;
                    }
                    taskLink   = $"View task: http://{_options.Value.SiteBaseUrl}/Admin/task/Details/{task.Id}";
                    taskSignup = task.AssignedVolunteers.FirstOrDefault(t => t.User.Id == volunteer.Id);
                }

                //set defaults for event signup
                var volunteerEmail       = !string.IsNullOrWhiteSpace(eventSignup?.PreferredEmail) ? eventSignup.PreferredEmail : volunteer.Email;
                var volunteerPhoneNumber = !string.IsNullOrWhiteSpace(eventSignup?.PreferredPhoneNumber) ? eventSignup.PreferredPhoneNumber : volunteer.PhoneNumber;
                var volunteerComments    = eventSignup?.AdditionalInfo ?? string.Empty;
                var remainingRequiredVolunteersPhrase = $"{campaignEvent.NumberOfUsersSignedUp}/{campaignEvent.NumberOfVolunteersRequired}";
                var typeOfSignupPhrase = "an event";

                if (campaignEvent.EventType != EventTypes.EventManaged)
                {
                    //set for task signup
                    volunteerEmail       = !string.IsNullOrWhiteSpace(taskSignup?.PreferredEmail) ? taskSignup.PreferredEmail : volunteerEmail;
                    volunteerPhoneNumber = !string.IsNullOrWhiteSpace(taskSignup?.PreferredPhoneNumber) ? taskSignup.PreferredPhoneNumber : volunteerPhoneNumber;
                    volunteerComments    = !string.IsNullOrWhiteSpace(taskSignup?.AdditionalInfo) ? taskSignup.AdditionalInfo : volunteerComments;
                    remainingRequiredVolunteersPhrase = $"{task.NumberOfUsersSignedUp}/{task.NumberOfVolunteersRequired}";
                    typeOfSignupPhrase = "a task";
                }

                var subject = $"A volunteer has signed up for {typeOfSignupPhrase}";

                var message = new StringBuilder();
                message.AppendLine($"A volunteer has signed up for {typeOfSignupPhrase}:");
                message.AppendLine();
                message.AppendLine($"   Campaign: {campaign.Name}");
                message.AppendLine($"   Event: {campaignEvent.Name} ({eventLink})");
                if (!IsEventSignup)
                {
                    message.AppendLine($"   Task: {task.Name} ({taskLink})");
                }
                message.AppendLine($"   Remaining/Required Volunteers: {remainingRequiredVolunteersPhrase}");
                message.AppendLine();
                message.AppendLine($"   Volunteer Name: {volunteer.Name}");
                message.AppendLine($"   Volunteer Email: {volunteerEmail}");
                message.AppendLine($"   Volunteer PhoneNumber: {volunteerPhoneNumber}");
                message.AppendLine($"   Volunteer Comments: {volunteerComments}");
                message.AppendLine();
                message.AppendLine(IsEventSignup ? GetEventSkillsInfo(campaignEvent, volunteer) : GetTaskSkillsInfo(task, volunteer));

                Debug.WriteLine(adminEmail);
                Debug.WriteLine(subject);
                Debug.WriteLine(message.ToString());

                if (!string.IsNullOrWhiteSpace(adminEmail))
                {
                    var command = new NotifyVolunteersCommand
                    {
                        ViewModel = new NotifyVolunteersViewModel
                        {
                            EmailMessage    = message.ToString(),
                            HtmlMessage     = message.ToString(),
                            EmailRecipients = new List <string> {
                                adminEmail
                            },
                            Subject = subject
                        }
                    };

                    await _mediator.SendAsync(command).ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"Exception encountered: message={e.Message}, innerException={e.InnerException}, stacktrace={e.StackTrace}");
            }
        }
Example #9
0
        protected override void LoadTestData()
        {
            var testOrg = new Organization
            {
                Name      = "My Test Campaign",
                LogoUrl   = "http://www.htbox.org/testCampaign",
                WebUrl    = "http://www.htbox.org",
                Campaigns = new List <Campaign>()
            };

            var testCampaign1 = new Campaign
            {
                Name = "Test Campaign 1",
                ManagingOrganization = testOrg,
                CampaignContacts     = new List <CampaignContact>()
            };

            var testCampaign2 = new Campaign
            {
                Name = "Test Campaign 2",
                ManagingOrganization = testOrg,
                CampaignContacts     = new List <CampaignContact>()
            };

            var primaryCampaignContact1 = new CampaignContact
            {
                ContactType = (int)ContactTypes.Primary,
                Contact     = new Contact
                {
                    Email = "*****@*****.**"
                }
            };

            var primaryCampaignContact2 = new CampaignContact
            {
                ContactType = (int)ContactTypes.Primary,
                Contact     = new Contact()
            };

            var testEvent1 = new Event
            {
                Id            = 5,
                Name          = "Test Event Name",
                Campaign      = testCampaign1,
                CampaignId    = testCampaign1.Id,
                StartDateTime = DateTime.UtcNow.AddDays(10),
                EndDateTime   = DateTime.UtcNow.AddDays(10).AddHours(8),
                Location      = new Location {
                    Id = 2
                },
                RequiredSkills = new List <EventSkill>()
            };

            var testEvent2 = new Event
            {
                Id            = 7,
                Name          = "Test Event 2",
                Campaign      = testCampaign2,
                CampaignId    = testCampaign2.Id,
                StartDateTime = DateTime.UtcNow.AddDays(3),
                EndDateTime   = DateTime.UtcNow.AddDays(3).AddHours(4),
                Location      = new Location {
                    Id = 5
                },
                RequiredSkills = new List <EventSkill>()
            };

            var username1 = $"*****@*****.**";
            var user1     = new ApplicationUser {
                UserName = username1, Email = username1, EmailConfirmed = true
            };

            Context.Users.Add(user1);

            var username2 = $"*****@*****.**";
            var user2     = new ApplicationUser {
                UserName = username2, Email = username2, EmailConfirmed = true
            };

            Context.Users.Add(user2);

            testCampaign1.CampaignContacts.Add(primaryCampaignContact1);
            testCampaign2.CampaignContacts.Add(primaryCampaignContact2);

            testOrg.Campaigns.Add(testCampaign1);
            testOrg.Campaigns.Add(testCampaign2);

            Context.Organizations.Add(testOrg);
            Context.Events.Add(testEvent1);
            Context.Events.Add(testEvent2);

            var testTask1 = new AllReadyTask
            {
                Id      = 7,
                Event   = testEvent1,
                EventId = testEvent1.Id
                          // Required Skills?
            };

            var testTask2 = new AllReadyTask
            {
                Id      = 9,
                Event   = testEvent2,
                EventId = testEvent2.Id
                          // Required Skills?
            };

            Context.Tasks.Add(testTask1);
            Context.Tasks.Add(testTask2);

            Context.SaveChanges();
        }
Example #10
0
        public static AllReadyTask ToModel(this TaskViewModel task, IAllReadyDataAccess dataAccess)
        {
            var activity = dataAccess.GetActivity(task.ActivityId);

            if (activity == null)
            {
                return(null);
            }

            bool         newTask = true;
            AllReadyTask dbtask;

            if (task.Id == 0)
            {
                dbtask = new AllReadyTask();
            }
            else
            {
                dbtask  = dataAccess.GetTask(task.Id);
                newTask = false;
            }

            dbtask.Id               = task.Id;
            dbtask.Description      = task.Description;
            dbtask.Activity         = activity;
            dbtask.EndDateTimeUtc   = task.EndDateTime.HasValue ? task.EndDateTime.Value.UtcDateTime : new Nullable <DateTime>();
            dbtask.StartDateTimeUtc = task.EndDateTime.HasValue ? task.StartDateTime.Value.UtcDateTime : new Nullable <DateTime>();
            dbtask.Name             = task.Name;

            // Workaround:  POST is bringing in empty AssignedVolunteers.  Clean this up. Discussing w/ Kiran Challa.
            // Workaround: the if statement is superflous, and should go away once we have the proper fix referenced above.
            if (task.AssignedVolunteers != null)
            {
                var bogusAssignedVolunteers = (from assignedVolunteer in task.AssignedVolunteers
                                               where string.IsNullOrEmpty(assignedVolunteer.UserId)
                                               select assignedVolunteer).ToList();
                foreach (var bogus in bogusAssignedVolunteers)
                {
                    task.AssignedVolunteers.Remove(bogus);
                }
            }
            // end workaround


            if (task.AssignedVolunteers != null && task.AssignedVolunteers.Count > 0)
            {
                var taskUsersList = task.AssignedVolunteers.Select(tvm => new TaskUsers
                {
                    Task = dbtask,
                    User = dataAccess.GetUser(tvm.UserId)
                }).ToList();

                // We may be updating an existing task
                if (newTask || dbtask.AssignedVolunteers.Count == 0)
                {
                    dbtask.AssignedVolunteers = taskUsersList;
                }
                else
                {
                    // Can probably rewrite this more efficiently.
                    foreach (TaskUsers taskUsers in taskUsersList)
                    {
                        if (!(from entry in dbtask.AssignedVolunteers
                              where entry.User.Id == taskUsers.User.Id
                              select entry).Any())
                        {
                            dbtask.AssignedVolunteers.Add(taskUsers);
                        }
                    }
                }
            }

            return(dbtask);
        }
        public EventDetailQueryHandlerTests()
        {
            var org = new Organization
            {
                Id   = 1,
                Name = "Organization"
            };

            var campaign = new Campaign
            {
                Id   = 1,
                Name = "Campaign",
                ManagingOrganization = org
            };

            var campaignEvent = new Models.Event
            {
                Id       = 1,
                Name     = "Event",
                Campaign = campaign
            };

            var task1 = new AllReadyTask
            {
                Id    = 1,
                Name  = "Task 1",
                Event = campaignEvent,
                NumberOfVolunteersRequired = 22
            };

            var task2 = new AllReadyTask
            {
                Id    = 2,
                Name  = "Task 2",
                Event = campaignEvent,
                NumberOfVolunteersRequired = 8
            };

            var user = new ApplicationUser {
                Id = Guid.NewGuid().ToString(), Email = "[email protected] "
            };
            var user2 = new ApplicationUser {
                Id = Guid.NewGuid().ToString(), Email = "[email protected] "
            };

            var taskSignup1 = new TaskSignup
            {
                User   = user,
                Task   = task1,
                Status = TaskStatus.Accepted.ToString()
            };

            var taskSignup2 = new TaskSignup
            {
                User   = user2,
                Task   = task1,
                Status = TaskStatus.Accepted.ToString()
            };

            var taskSignup3 = new TaskSignup
            {
                User   = user,
                Task   = task2,
                Status = TaskStatus.Accepted.ToString()
            };

            Context.Add(campaign);
            Context.Add(campaignEvent);
            Context.Add(task1);
            Context.Add(task2);
            Context.Add(user);
            Context.Add(user2);
            Context.Add(taskSignup1);
            Context.Add(taskSignup2);
            Context.Add(taskSignup3);
            Context.SaveChanges();
        }
Example #12
0
        public static AllReadyTask ToModel(this TaskViewModel taskViewModel, IAllReadyDataAccess dataAccess)
        {
            var activity = dataAccess.GetActivity(taskViewModel.ActivityId);

            if (activity == null)
                return null;

            bool newTask = true;
            AllReadyTask dbtask;

            if (taskViewModel.Id == 0)
            {
                dbtask = new AllReadyTask();
            }
            else
            {
                dbtask = dataAccess.GetTask(taskViewModel.Id);
                newTask = false;
            }

            dbtask.Id = taskViewModel.Id;
            dbtask.Description = taskViewModel.Description;
            dbtask.Activity = activity;
            dbtask.EndDateTimeUtc = taskViewModel.EndDateTime.HasValue ? taskViewModel.EndDateTime.Value.UtcDateTime : new Nullable<DateTime>();
            dbtask.StartDateTimeUtc = taskViewModel.EndDateTime.HasValue ? taskViewModel.StartDateTime.Value.UtcDateTime : new Nullable<DateTime>();
            dbtask.Name = taskViewModel.Name;
            dbtask.RequiredSkills = dbtask.RequiredSkills ?? new List<TaskSkill>();
            taskViewModel.RequiredSkills = taskViewModel.RequiredSkills ?? new List<int>();
            ////Remove old skills
            //dbtask.RequiredSkills.RemoveAll(ts => !taskViewModel.RequiredSkills.Any(s => ts.SkillId == s));
            ////Add new skills
            //dbtask.RequiredSkills.AddRange(taskViewModel.RequiredSkills
            //    .Where(rs => !dbtask.RequiredSkills.Any(ts => ts.SkillId == rs))
            //    .Select(rs => new TaskSkill() { SkillId = rs, TaskId = taskViewModel.Id }));

            // Workaround:  POST is bringing in empty AssignedVolunteers.  Clean this up. Discussing w/ Kiran Challa.
            // Workaround: the if statement is superflous, and should go away once we have the proper fix referenced above.
            if (taskViewModel.AssignedVolunteers != null)
            {
                var bogusAssignedVolunteers = (from assignedVolunteer in taskViewModel.AssignedVolunteers
                                               where string.IsNullOrEmpty(assignedVolunteer.UserId)
                                               select assignedVolunteer).ToList();
                foreach (var bogus in bogusAssignedVolunteers)
                {
                    taskViewModel.AssignedVolunteers.Remove(bogus);
                }
            }
            // end workaround

            if (taskViewModel.AssignedVolunteers != null && taskViewModel.AssignedVolunteers.Count > 0)
            {
                var taskUsersList = taskViewModel.AssignedVolunteers.Select(tvm => new TaskSignup
                {
                    Task = dbtask,
                    User = dataAccess.GetUser(tvm.UserId)
                }).ToList();

                // We may be updating an existing task
                if (newTask || dbtask.AssignedVolunteers.Count == 0)
                {
                    dbtask.AssignedVolunteers = taskUsersList;
                }
                else
                {
                    // Can probably rewrite this more efficiently.
                    foreach (TaskSignup taskUsers in taskUsersList)
                    {
                        if (!(from entry in dbtask.AssignedVolunteers
                              where entry.User.Id == taskUsers.User.Id
                              select entry).Any())
                        {
                            dbtask.AssignedVolunteers.Add(taskUsers);
                        }
                    }
                }
            }

            return dbtask;
        }
 static IEnumerable <TaskSkill> CloneTaskRequiredSkills(AllReadyTask task)
 {
     return(task.RequiredSkills.Select(taskSkill => new TaskSkill {
         SkillId = taskSkill.SkillId
     }));
 }
        protected override void LoadTestData()
        {
            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>(),
                EventType      = EventType.Itinerary
            };

            var itinerary = new Itinerary
            {
                Event = queenAnne,
                Name  = "1st Itinerary",
                Id    = 1,
                Date  = new DateTime(2016, 07, 01)
            };

            var task = new AllReadyTask
            {
                Id            = 1,
                Event         = queenAnne,
                Name          = "A Task",
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime   = new DateTime(2015, 7, 4, 18, 0, 0).ToUniversalTime()
            };

            var user = new ApplicationUser
            {
                Id    = Guid.NewGuid().ToString(),
                Email = "*****@*****.**"
            };

            var taskSignup = new TaskSignup
            {
                Id        = 1,
                User      = user,
                Task      = task,
                Itinerary = itinerary
            };

            var request = new Request
            {
                RequestId = Guid.NewGuid(),
                Name      = "Request 1",
                Address   = "Street Name 1",
                City      = "Seattle"
            };

            var itineraryReq = new ItineraryRequest
            {
                Request   = request,
                Itinerary = itinerary
            };

            Context.Organizations.Add(htb);
            Context.Campaigns.Add(firePrev);
            Context.Events.Add(queenAnne);
            Context.Itineraries.Add(itinerary);
            Context.Tasks.Add(task);
            Context.Users.Add(user);
            Context.Requests.Add(request);
            Context.ItineraryRequests.Add(itineraryReq);
            Context.TaskSignups.Add(taskSignup);
            Context.SaveChanges();
        }
Example #15
0
 public static TaskViewModel ToViewModel(this AllReadyTask task)
 {
     return(new TaskViewModel(task));
 }
Example #16
0
        public void IsClosed_ShouldBeFalse_IfEndDateIsNull()
        {
            var sut = new AllReadyTask();

            Assert.False(sut.IsClosed);
        }
Example #17
0
        public static AllReadyTask ToModel(this TaskViewModel taskViewModel, IMediator mediator)
        {
            var activity = mediator.Send(new ActivityByActivityIdQuery {
                ActivityId = taskViewModel.ActivityId
            });

            if (activity == null)
            {
                return(null);
            }

            var          newTask = true;
            AllReadyTask dbtask;

            if (taskViewModel.Id == 0)
            {
                dbtask = new AllReadyTask();
            }
            else
            {
                dbtask = mediator.Send(new TaskByTaskIdQuery {
                    TaskId = taskViewModel.Id
                });
                newTask = false;
            }

            dbtask.Id                    = taskViewModel.Id;
            dbtask.Description           = taskViewModel.Description;
            dbtask.Activity              = activity;
            dbtask.EndDateTime           = taskViewModel.EndDateTime.HasValue ? taskViewModel.EndDateTime.Value.UtcDateTime : new DateTime?();
            dbtask.StartDateTime         = taskViewModel.EndDateTime.HasValue ? taskViewModel.StartDateTime.Value.UtcDateTime : new DateTime?();
            dbtask.Name                  = taskViewModel.Name;
            dbtask.RequiredSkills        = dbtask.RequiredSkills ?? new List <TaskSkill>();
            taskViewModel.RequiredSkills = taskViewModel.RequiredSkills ?? new List <int>();
            ////Remove old skills
            //dbtask.RequiredSkills.RemoveAll(ts => !taskViewModel.RequiredSkills.Any(s => ts.SkillId == s));
            ////Add new skills
            //dbtask.RequiredSkills.AddRange(taskViewModel.RequiredSkills
            //    .Where(rs => !dbtask.RequiredSkills.Any(ts => ts.SkillId == rs))
            //    .Select(rs => new TaskSkill() { SkillId = rs, TaskId = taskViewModel.Id }));

            // Workaround:  POST is bringing in empty AssignedVolunteers.  Clean this up. Discussing w/ Kiran Challa.
            // Workaround: the if statement is superflous, and should go away once we have the proper fix referenced above.
            if (taskViewModel.AssignedVolunteers != null)
            {
                var bogusAssignedVolunteers = (from assignedVolunteer in taskViewModel.AssignedVolunteers
                                               where string.IsNullOrEmpty(assignedVolunteer.UserId)
                                               select assignedVolunteer).ToList();
                foreach (var bogus in bogusAssignedVolunteers)
                {
                    taskViewModel.AssignedVolunteers.Remove(bogus);
                }
            }
            // end workaround

            if (taskViewModel.AssignedVolunteers != null && taskViewModel.AssignedVolunteers.Count > 0)
            {
                var taskUsersList = taskViewModel.AssignedVolunteers.Select(tvm => new TaskSignup
                {
                    Task = dbtask,
                    User = mediator.Send(new UserByUserIdQuery {
                        UserId = tvm.UserId
                    })
                }).ToList();

                // We may be updating an existing task
                if (newTask || dbtask.AssignedVolunteers.Count == 0)
                {
                    dbtask.AssignedVolunteers = taskUsersList;
                }
                else
                {
                    // Can probably rewrite this more efficiently.
                    foreach (var taskUsers in taskUsersList)
                    {
                        if (!(from entry in dbtask.AssignedVolunteers
                              where entry.User.Id == taskUsers.User.Id
                              select entry).Any())
                        {
                            dbtask.AssignedVolunteers.Add(taskUsers);
                        }
                    }
                }
            }

            return(dbtask);
        }
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService <AllReadyContext>();
            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
            };

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

            var username1 = $"*****@*****.**";

            var user1 = new ApplicationUser {
                UserName = username1, Email = username1, EmailConfirmed = true
            };

            context.Users.Add(user1);

            htb.Campaigns.Add(firePrev);
            context.Organizations.Add(htb);
            context.Activities.Add(queenAnne);

            var activitySignups = new List <ActivitySignup>
            {
                new ActivitySignup {
                    Activity = queenAnne, User = user1, SignupDateTime = DateTime.UtcNow
                }
            };

            context.ActivitySignup.AddRange(activitySignups);

            var newTask = new AllReadyTask()
            {
                Activity      = queenAnne,
                Description   = "Description of a very important task",
                Name          = "Task # 1",
                EndDateTime   = DateTime.Now.AddDays(5),
                StartDateTime = DateTime.Now.AddDays(3),
                Organization  = htb
            };

            newTask.AssignedVolunteers.Add(new TaskSignup()
            {
                Task = newTask,
                User = user1
            });

            context.Tasks.Add(newTask);

            context.SaveChanges();
        }
Example #19
0
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService <AllReadyContext>();

            _user1 = new ApplicationUser
            {
                UserName  = "******",
                FirstName = "John",
                LastName  = "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 Models.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>(),
                Tasks          = new List <AllReadyTask>(),
                UsersSignedUp  = new List <EventSignup>
                {
                    new EventSignup
                    {
                        Id                   = 1,
                        PreferredEmail       = "*****@*****.**",
                        PreferredPhoneNumber = "(555)555-1234",
                        User                 = _user1
                    }
                }
            };

            _task1 = new AllReadyTask
            {
                Id            = 1,
                Event         = _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.Events.Add(_queenAnne);
            context.SaveChanges();
        }
Example #20
0
        private async Task <AllReadyTask> ToModel(TaskViewModel taskViewModel, IMediator mediator)
        {
            var @event = await mediator.SendAsync(new EventByEventIdQuery { EventId = taskViewModel.EventId });

            if (@event == null)
            {
                return(null);
            }

            var          newTask = true;
            AllReadyTask allReadyTask;

            if (taskViewModel.Id == 0)
            {
                allReadyTask = new AllReadyTask();
            }
            else
            {
                allReadyTask = await mediator.SendAsync(new TaskByTaskIdQuery { TaskId = taskViewModel.Id });

                newTask = false;
            }

            allReadyTask.Id              = taskViewModel.Id;
            allReadyTask.Description     = taskViewModel.Description;
            allReadyTask.Event           = @event;
            allReadyTask.EndDateTime     = taskViewModel.EndDateTime.UtcDateTime;
            allReadyTask.StartDateTime   = taskViewModel.StartDateTime.UtcDateTime;
            allReadyTask.Name            = taskViewModel.Name;
            allReadyTask.RequiredSkills  = allReadyTask.RequiredSkills ?? new List <TaskSkill>();
            taskViewModel.RequiredSkills = taskViewModel.RequiredSkills ?? new List <int>();
            ////Remove old skills
            //dbtask.RequiredSkills.RemoveAll(ts => !taskViewModel.RequiredSkills.Any(s => ts.SkillId == s));
            ////Add new skills
            //dbtask.RequiredSkills.AddRange(taskViewModel.RequiredSkills
            //    .Where(rs => !dbtask.RequiredSkills.Any(ts => ts.SkillId == rs))
            //    .Select(rs => new TaskSkill() { SkillId = rs, TaskId = taskViewModel.Id }));

            // Workaround:  POST is bringing in empty AssignedVolunteers.  Clean this up. Discussing w/ Kiran Challa.
            // Workaround: the if statement is superflous, and should go away once we have the proper fix referenced above.
            if (taskViewModel.AssignedVolunteers != null)
            {
                var bogusAssignedVolunteers = (from assignedVolunteer in taskViewModel.AssignedVolunteers
                                               where string.IsNullOrEmpty(assignedVolunteer.UserId)
                                               select assignedVolunteer).ToList();
                foreach (var bogus in bogusAssignedVolunteers)
                {
                    taskViewModel.AssignedVolunteers.Remove(bogus);
                }
            }
            // end workaround

            if (taskViewModel.AssignedVolunteers != null && taskViewModel.AssignedVolunteers.Count > 0)
            {
                var assignedVolunteers = taskViewModel.AssignedVolunteers.ToList();

                var taskUsersList = await assignedVolunteers.ToTaskSignups(allReadyTask, _mediator);

                // We may be updating an existing task
                if (newTask || allReadyTask.AssignedVolunteers.Count == 0)
                {
                    allReadyTask.AssignedVolunteers = taskUsersList;
                }
                else
                {
                    // Can probably rewrite this more efficiently.
                    foreach (var taskUsers in taskUsersList)
                    {
                        if (!(from entry in allReadyTask.AssignedVolunteers
                              where entry.User.Id == taskUsers.User.Id
                              select entry).Any())
                        {
                            allReadyTask.AssignedVolunteers.Add(taskUsers);
                        }
                    }
                }
            }
            return(allReadyTask);
        }