private static TaskSignup CreateTaskSignup(int taskSignupId, int taskId, string email, string firstName = null, string lastName = null, string userMail = null)
        {
            var taskSignup = new TaskSignup
            {
                Id   = taskSignupId,
                User = new ApplicationUser
                {
                    FirstName = firstName,
                    LastName  = lastName,
                    Email     = userMail
                },
                Task = new AllReadyTask
                {
                    Id    = taskId,
                    Event = new AllReady.Models.Event
                    {
                        Campaign = new Campaign
                        {
                            CampaignContacts = new List <CampaignContact>
                            {
                                new CampaignContact
                                {
                                    ContactType = (int)ContactTypes.Primary,
                                    Contact     = new Contact {
                                        Email = email
                                    }
                                }
                            }
                        }
                    }
                }
            };

            return(taskSignup);
        }
Esempio n. 2
0
        public void SetTaskIdAndTaskName_WhenTaskSignupsTaskIsNotNull()
        {
            var taskSignup = new TaskSignup {
                Task = new AllReadyTask {
                    Id = 1, Name = "TaskName"
                }
            };
            var sut = new TaskSignupViewModel(taskSignup);

            Assert.Equal(sut.TaskId, taskSignup.Task.Id);
            Assert.Equal(sut.TaskName, taskSignup.Task.Name);
        }
Esempio n. 3
0
        public void SetUserIdAndUserName_WhenTaskSignupsUserIsNotNull()
        {
            var taskSignup = new TaskSignup {
                User = new ApplicationUser {
                    Id = "1", UserName = "******"
                }
            };
            var sut = new TaskSignupViewModel(taskSignup);

            Assert.Equal(sut.UserId, taskSignup.User.Id);
            Assert.Equal(sut.UserName, taskSignup.User.UserName);
        }
        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 taskSignUp = new TaskSignup {
                Id = 1, ItineraryId = 2, TaskId = 1
            };

            Context.Organizations.Add(htb);
            Context.Campaigns.Add(firePrev);
            Context.Events.Add(queenAnne);
            Context.Itineraries.Add(itinerary);
            Context.TaskSignups.Add(taskSignUp);

            Context.SaveChanges();
        }
        public async Task <bool> Handle(AddTeamMemberCommand message)
        {
            var itinerary = await _context.Itineraries
                            .Where(x => x.Id == message.ItineraryId)
                            .Select(x => new { x.EventId, x.Date })
                            .SingleOrDefaultAsync()
                            .ConfigureAwait(false);

            if (itinerary == null)
            {
                // todo: sgordon: enhance this with a error message so the controller can better respond to the issue
                return(false);
            }

            // We requery for potential team members in case something has changed or the task signup id was modified before posting
            var potentialTaskSignups = await _mediator.SendAsync(new PotentialItineraryTeamMembersQuery { EventId = itinerary.EventId, Date = itinerary.Date })
                                       .ConfigureAwait(false);

            var matchedSignup = false;

            foreach (var signup in potentialTaskSignups)
            {
                var id = int.Parse(signup.Value);
                if (id == message.TaskSignupId)
                {
                    matchedSignup = true;
                    break;
                }
            }

            if (matchedSignup)
            {
                var taskSignup = new TaskSignup
                {
                    Id          = message.TaskSignupId,
                    ItineraryId = message.ItineraryId
                };

                _context.TaskSignups.Attach(taskSignup);
                _context.Entry(taskSignup).Property(x => x.ItineraryId).IsModified = true;
                await _context.SaveChangesAsync().ConfigureAwait(false);

                await _mediator
                .PublishAsync(new IntineraryVolunteerListUpdated { TaskSignupId = message.TaskSignupId, ItineraryId = message.ItineraryId, UpdateType = UpdateType.VolunteerAssigned })
                .ConfigureAwait(false);
            }

            return(true);
        }
        protected override async Task HandleCore(AssignTaskCommand message)
        {
            var task = await _context.Tasks.SingleAsync(c => c.Id == message.TaskId).ConfigureAwait(false);

            var taskSignups = new List <TaskSignup>();

            //New Items, if not in collection add them, save that list for the pub-event
            foreach (var userId in message.UserIds)
            {
                var taskSignup = task.AssignedVolunteers.SingleOrDefault(a => a.User.Id == userId);
                if (taskSignup != null)
                {
                    continue;
                }

                var user = await _context.Users.SingleAsync(u => u.Id == userId);

                taskSignup = new TaskSignup
                {
                    Task              = task,
                    User              = user,
                    AdditionalInfo    = string.Empty,
                    Status            = TaskStatus.Assigned.ToString(),
                    StatusDateTimeUtc = DateTime.UtcNow
                };

                task.AssignedVolunteers.Add(taskSignup);
                taskSignups.Add(taskSignup);
            }

            //Remove task signups where the the user id is not included in the current list of assigned user id's
            var taskSignupsToRemove = task.AssignedVolunteers.Where(taskSignup => message.UserIds.All(uid => uid != taskSignup.User.Id)).ToList();

            taskSignupsToRemove.ForEach(taskSignup => task.AssignedVolunteers.Remove(taskSignup));

            await _context.SaveChangesAsync().ConfigureAwait(false);

            await _mediator.PublishAsync(new TaskAssignedToVolunteersNotification
            {
                TaskId = message.TaskId,
                NewlyAssignedVolunteers = taskSignups.Select(x => x.User.Id).ToList()
            })
            .ConfigureAwait(false);
        }
Esempio n. 7
0
        public TaskSignupViewModel(TaskSignup taskSignup)
        {
            Id                = taskSignup.Id;
            Status            = taskSignup.Status.ToString();
            StatusDateTimeUtc = taskSignup.StatusDateTimeUtc;
            StatusDescription = taskSignup.StatusDescription;

            if (taskSignup.Task != null)
            {
                TaskId   = taskSignup.Task.Id;
                TaskName = taskSignup.Task.Name;
            }

            if (taskSignup.User != null)
            {
                UserId   = taskSignup.User.Id;
                UserName = taskSignup.User.UserName;
            }
        }
Esempio n. 8
0
        public TasksByApplicationUserIdQueryHandlerShould()
        {
            message = new TasksByApplicationUserIdQuery {
                ApplicationUserId = Guid.NewGuid().ToString()
            };
            alreadyTask = new AllReadyTask {
                Name = "name"
            };
            task = new TaskSignup {
                User = new ApplicationUser {
                    Id = message.ApplicationUserId
                }, Task = alreadyTask
            };

            Context.Add(alreadyTask);
            Context.Add(task);
            Context.SaveChanges();

            sut = new TasksByApplicationUserIdQueryHandler(Context);
        }
Esempio n. 9
0
        protected override void LoadTestData()
        {
            _user = new ApplicationUser
            {
                PhoneNumber = "123",
                Email       = "*****@*****.**"
            };

            _taskSignup = new TaskSignup
            {
                Id                   = 1,
                PreferredEmail       = "*****@*****.**",
                PreferredPhoneNumber = "456",
                User                 = _user
            };

            _taskSignupNoContactPreferences = new TaskSignup
            {
                Id   = 2,
                User = _user
            };

            _taskSignupNoContacts = new TaskSignup
            {
                Id   = 3,
                User = new ApplicationUser()
            };

            _itinerary = new Itinerary
            {
                Id   = 1,
                Date = _itineraryDate = new DateTime(2016, 1, 1, 10, 30, 0)
            };

            Context.Users.Add(_user);
            Context.TaskSignups.Add(_taskSignup);
            Context.TaskSignups.Add(_taskSignupNoContactPreferences);
            Context.TaskSignups.Add(_taskSignupNoContacts);
            Context.Itineraries.Add(_itinerary);
            Context.SaveChanges();
        }
Esempio n. 10
0
        protected override async Task HandleCore(AssignTaskCommandAsync message)
        {
            var task          = GetTask(message);
            var campaignEvent = task.Event;
            var taskSignups   = new List <TaskSignup>();

            if (task != null)
            {
                //New Items, if not in collection add them, save that list for the pub-event
                foreach (var userId in message.UserIds)
                {
                    var taskSignup = task.AssignedVolunteers.SingleOrDefault(a => a.User.Id == userId);
                    if (taskSignup == null)
                    {
                        var user = _context.Users.Single(u => u.Id == userId);
                        taskSignup = new TaskSignup
                        {
                            Task                 = task,
                            User                 = user,
                            PreferredEmail       = user.Email,
                            PreferredPhoneNumber = user.PhoneNumber,
                            AdditionalInfo       = string.Empty,
                            Status               = TaskStatus.Assigned.ToString(),
                            StatusDateTimeUtc    = DateTime.UtcNow
                        };

                        task.AssignedVolunteers.Add(taskSignup);
                        taskSignups.Add(taskSignup);

                        // If the user has not already been signed up for the event, sign them up
                        if (campaignEvent.UsersSignedUp.All(acsu => acsu.User.Id != userId))
                        {
                            campaignEvent.UsersSignedUp.Add(new EventSignup
                            {
                                Event                = campaignEvent,
                                User                 = user,
                                PreferredEmail       = user.Email,
                                PreferredPhoneNumber = user.PhoneNumber,
                                AdditionalInfo       = string.Empty,
                                SignupDateTime       = DateTime.UtcNow
                            });
                        }
                    }
                }

                //Remove task signups where the the user id is not included in the current list of assigned user id's
                var taskSignupsToRemove = task.AssignedVolunteers.Where(taskSignup => message.UserIds.All(uid => uid != taskSignup.User.Id)).ToList();
                taskSignupsToRemove.ForEach(taskSignup => task.AssignedVolunteers.Remove(taskSignup));

                // delete the event signups where the user is no longer signed up for any tasks
                (from taskSignup in taskSignupsToRemove
                 where !campaignEvent.IsUserInAnyTask(taskSignup.User.Id)
                 select campaignEvent.UsersSignedUp.FirstOrDefault(u => u.User.Id == taskSignup.User.Id))
                .ToList()
                .ForEach(signup => campaignEvent.UsersSignedUp.Remove(signup));
            }
            await _context.SaveChangesAsync();

            // send all notifications to the queue
            var smsRecipients   = new List <string>();
            var emailRecipients = new List <string>();

            // get all confirmed contact points for the broadcast
            smsRecipients.AddRange(taskSignups.Where(u => u.User.PhoneNumberConfirmed).Select(v => v.User.PhoneNumber));
            emailRecipients.AddRange(taskSignups.Where(u => u.User.EmailConfirmed).Select(v => v.User.Email));

            var command = new NotifyVolunteersCommand
            {
                ViewModel = new NotifyVolunteersViewModel
                {
                    SmsMessage      = "You've been assigned a task from AllReady.",
                    SmsRecipients   = smsRecipients,
                    EmailMessage    = "You've been assigned a task from AllReady.",
                    HtmlMessage     = "You've been assigned a task from AllReady.",
                    EmailRecipients = emailRecipients,
                    Subject         = "You've been assigned a task from AllReady."
                }
            };

            await _mediator.SendAsync(command);
        }
Esempio n. 11
0
        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();
        }
        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();
        }
        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();
        }
Esempio n. 14
0
        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}");
            }
        }
        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();
        }
Esempio n. 16
0
        protected override void HandleCore(AssignTaskCommand message)
        {
            var task          = _context.Tasks.SingleOrDefault(c => c.Id == message.TaskId);
            var newVolunteers = new List <TaskSignup>();

            if (task != null)
            {
                //New Items, if not in collection add them, save that list for the pub-event
                foreach (var userId in message.UserIds)
                {
                    var av = task.AssignedVolunteers.SingleOrDefault(a => a.User.Id == userId);
                    if (av == null)
                    {
                        var volunteerUser = _context.Users.Single(u => u.Id == userId);
                        av = new TaskSignup
                        {
                            Task              = task,
                            User              = volunteerUser,
                            Status            = TaskStatus.Assigned.ToString(),
                            StatusDateTimeUtc = DateTime.UtcNow
                        };
                    }
                    task.AssignedVolunteers.Add(av);
                    newVolunteers.Add(av);
                }
                //Remove Items Not there, All Volunteers should be in task.AssignedVolunteers
                var removedVolunteers = new List <TaskSignup>();
                foreach (var vol in task.AssignedVolunteers)
                {
                    if (!message.UserIds.Any(uid => uid == vol.User.Id))
                    {
                        removedVolunteers.Add(vol);
                    }
                }
                foreach (var vol in removedVolunteers)
                {
                    task.AssignedVolunteers.Remove(vol);
                }
            }
            _context.SaveChanges();

            // send all notifications to the queue
            var smsRecipients   = new List <string>();
            var emailRecipients = new List <string>();

            // get all confirmed contact points for the broadcast
            smsRecipients.AddRange(newVolunteers.Where(u => u.User.PhoneNumberConfirmed).Select(v => v.User.PhoneNumber));
            emailRecipients.AddRange(newVolunteers.Where(u => u.User.EmailConfirmed).Select(v => v.User.Email));

            var command = new NotifyVolunteersCommand
            {
                ViewModel = new NotifyVolunteersViewModel
                {
                    SmsMessage      = "You've been assigned a task from AllReady.",
                    SmsRecipients   = smsRecipients,
                    EmailMessage    = "You've been assigned a task from AllReady.",
                    HtmlMessage     = "You've been assigned a task from AllReady.",
                    EmailRecipients = emailRecipients,
                    Subject         = "You've been assigned a task from AllReady."
                }
            };

            _bus.Send(command);
        }