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 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
            {
                Activity = 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.Activities.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();
        }
コード例 #2
0
ファイル: EditActivity.cs プロジェクト: fr33k3r/allReady
        public void ExistingActivity()
        {
            var context = ServiceProvider.GetService<AllReadyContext>();
            Tenant htb = new Tenant()
            {
                Id = 123,
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };
            Campaign firePrev = new Campaign()
            {
                Id = 1,
                Name = "Neighborhood Fire Prevention Days",
                ManagingTenant = htb
            };
            htb.Campaigns.Add(firePrev);
            Activity queenAnne = new Activity()
            {
                Id = 100,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTimeUtc = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTimeUtc = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<ActivitySkill>()
            };
            context.Tenants.Add(htb);
            context.Activities.Add(queenAnne);
            context.SaveChanges();

            const string NEW_NAME = "Some new name value";

            var vm = new ActivityDetailModel
            {
                CampaignId = queenAnne.CampaignId,
                CampaignName = queenAnne.Campaign.Name,
                Description = queenAnne.Description,
                EndDateTime = queenAnne.EndDateTimeUtc,
                Id = queenAnne.Id,
                ImageUrl = queenAnne.ImageUrl,
                Location = null,
                Name = NEW_NAME,
                RequiredSkills = queenAnne.RequiredSkills,
                StartDateTime = queenAnne.StartDateTimeUtc,
                Tasks = null,
                TenantId = queenAnne.Campaign.ManagingTenantId,
                TenantName = queenAnne.Campaign.ManagingTenant.Name,
                Volunteers = null
            };
            var query = new EditActivityCommand { Activity = vm };
            var handler = new EditActivityCommandHandler(context);
            var result = handler.Handle(query);
            Assert.Equal(100, result); // should get back the activity id

            var data = context.Activities.Single(_ => _.Id == result);
            Assert.Equal(NEW_NAME, data.Name);
        }
コード例 #3
0
        public void GetCampaignsByPostalCodeReturnsCorrectResults()
        {
            var activity1 = new Activity { Id = 1, CampaignId = 1 };
            activity1.Campaign = new Campaign { Id = 1, Activities = new List<Activity> { activity1 }, ManagingOrganization = new Organization() };

            var activity2 = new Activity { Id = 2 };
            var activity3 = new Activity { Id = 3 };
            var campaign2 = new Campaign { Id = 2, Activities = new List<Activity> { activity2, activity3 }, ManagingOrganization = new Organization() };

            activity2.CampaignId = campaign2.Id;
            activity2.Campaign = campaign2;

            activity3.CampaignId = campaign2.Id;
            activity3.Campaign = campaign2;

            var allActivities = new List<Activity> { activity1, activity2, activity3 };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<AcitivitiesByPostalCodeQuery>())).Returns(allActivities);

            var sut = new CampaignApiController(mediator.Object);
            var results = sut.GetCampaignsByPostalCode(It.IsAny<string>(), It.IsAny<int>());

            Assert.Equal(results.Count(), allActivities.Count);
        }
コード例 #4
0
 protected override void LoadTestData()
 {
     var context = ServiceProvider.GetService<AllReadyContext>();
     Tenant htb = new Tenant()
     {
         Name = "Humanitarian Toolbox",
         LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
         WebUrl = "http://www.htbox.org",
         Campaigns = new List<Campaign>()
     };
     Campaign firePrev = new Campaign()
     {
         Name = "Neighborhood Fire Prevention Days",
         ManagingTenant = htb
     };
     htb.Campaigns.Add(firePrev);
     Activity queenAnne = new Activity()
     {
         Id = 1,
         Name = "Queen Anne Fire Prevention Day",
         Campaign = firePrev,
         CampaignId = firePrev.Id,
         StartDateTimeUtc = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
         EndDateTimeUtc = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
         Location = new Location { Id = 1 },
         Tenant = htb,
         RequiredSkills = new List<ActivitySkill>()
     };
     context.Tenants.Add(htb);
     context.Activities.Add(queenAnne);
     context.SaveChanges();
 }
コード例 #5
0
ファイル: ActivityViewModel.cs プロジェクト: fr33k3r/allReady
        public ActivityViewModel(Activity activity)
        {
            Id = activity.Id;
            if (activity.Campaign != null)
            {
                CampaignId = activity.Campaign.Id;
                CampaignName = activity.Campaign.Name;
            }

            Title = activity.Name;
            Description = activity.Description;

            StartDateTime = new DateTimeOffset(activity.StartDateTimeUtc, TimeSpan.Zero);
            EndDateTime = new DateTimeOffset(activity.EndDateTimeUtc, TimeSpan.Zero);

            if (activity.Location != null)
            {
                Location = new LocationViewModel(activity.Location);
            }

            ImageUrl = activity.ImageUrl;

            //TODO Location
            Tasks = activity.Tasks != null
                 ? new List<TaskViewModel>(activity.Tasks.Select(data => new TaskViewModel(data)).OrderBy(task => task.StartDateTime))
                 : new List<TaskViewModel>();

            RequiredSkills = activity.RequiredSkills?.Select(acsk => acsk.Skill).ToList();
        }
コード例 #6
0
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService<AllReadyContext>();
            Tenant htb = new Tenant()
            {
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };
            Campaign firePrev = new Campaign()
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingTenant = htb
            };
            Activity queenAnne = new Activity()
            {
                Id = 1,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTimeUtc = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTimeUtc = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<ActivitySkill>(),
            };

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

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

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

            var activitySignups = new List<ActivitySignup>();
            activitySignups.Add(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",
                EndDateTimeUtc = DateTime.Now.AddDays(5),
                StartDateTimeUtc = DateTime.Now.AddDays(3),
                Tenant = htb
            };
            newTask.AssignedVolunteers.Add(new TaskSignup()
            {
                Task = newTask,
                User = user1
            });
            context.Tasks.Add(newTask);

            context.SaveChanges();
        }
コード例 #7
0
 Task IAllReadyDataAccess.UpdateActivity(Activity value)
 {
     //First remove any skills that are no longer associated with this activity
     var acsksToRemove = _dbContext.ActivitySkills.Where(acsk => acsk.ActivityId == value.Id && (value.RequiredSkills == null ||
         !value.RequiredSkills.Any(acsk1 => acsk1.SkillId == acsk.SkillId)));
     _dbContext.ActivitySkills.RemoveRange(acsksToRemove);
     _dbContext.Activities.Update(value);
     return _dbContext.SaveChangesAsync();
 }
コード例 #8
0
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService<AllReadyContext>();

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

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

            var firePrev = new Campaign
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb
            };
            htb.Campaigns.Add(firePrev);

            var queenAnne = new Activity
            {
                Id = 1,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<ActivitySkill>()
            };
            context.PostalCodes.Add(seattlePostalCode);
            context.Locations.Add(seattle);
            context.Organizations.Add(htb);
            context.Activities.Add(queenAnne);
            context.SaveChanges();
        }
コード例 #9
0
        public ActivityViewModel(Activity activity, bool isUserSignedUp, string userId)
            : this(activity)
        {
            IsUserVolunteeredForActivity = isUserSignedUp.ToString().ToLowerInvariant();
            UserId = userId;

            if (string.IsNullOrWhiteSpace(UserId) || !isUserSignedUp)
            {
                Tasks = new List<TaskViewModel>();
            }
            else
            {
                var assignedTasks = activity.Tasks.Where(t => t.AssignedVolunteers.Any(au => au.User.Id == UserId)).ToList();
                Tasks = new List<TaskViewModel>(assignedTasks.Select(data => new TaskViewModel(data, UserId)).OrderBy(task => task.StartDateTime));
            }
        }
コード例 #10
0
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService<AllReadyContext>();
            Organization htb = new Organization()
            {
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };
            Campaign firePrev = new Campaign()
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb
            };
            Activity 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 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);
            context.Activities.Add(queenAnne);
            
            var activitySignups = new List<ActivitySignup>();
            activitySignups.Add(new ActivitySignup { Activity = queenAnne, User = user1, SignupDateTime = DateTime.UtcNow });
            activitySignups.Add(new ActivitySignup { Activity = queenAnne, User = user2, SignupDateTime = DateTime.UtcNow });

            context.ActivitySignup.AddRange(activitySignups);
            context.SaveChanges();
        }
コード例 #11
0
        public ActivityViewModel(Activity activity)
        {
            Id = activity.Id;
            if (activity.Campaign != null)
            {
                CampaignId = activity.Campaign.Id;
                CampaignName = activity.Campaign.Name;
                TimeZoneId = activity.Campaign.TimeZoneId;
                if (activity.Campaign.ManagingOrganization != null)
                {
                    OrganizationId = activity.Campaign.ManagingOrganization.Id;
                    OrganizationName = activity.Campaign.ManagingOrganization.Name;
                    HasPrivacyPolicy = !string.IsNullOrEmpty(activity.Campaign.ManagingOrganization.PrivacyPolicy);
                }
            }

            Title = activity.Name;
            Description = activity.Description;
            ActivityType = activity.ActivityType;
            StartDateTime = activity.StartDateTime;
            EndDateTime = activity.EndDateTime;

            if (activity.Location != null)
            {
                Location = new LocationViewModel(activity.Location);
            }

            IsClosed = EndDateTime.UtcDateTime < DateTimeOffset.UtcNow;

            ImageUrl = activity.ImageUrl;

            //TODO Location
            Tasks = activity.Tasks != null
                 ? new List<TaskViewModel>(activity.Tasks.Select(data => new TaskViewModel(data)).OrderBy(task => task.StartDateTime))
                 : new List<TaskViewModel>();

            SignupModel = new ActivitySignupViewModel();

            RequiredSkills = activity.RequiredSkills?.Select(acsk => acsk.Skill).ToList();
            IsLimitVolunteers = activity.IsLimitVolunteers;
            IsAllowWaitList = activity.IsAllowWaitList;
            
        }
コード例 #12
0
        public void CreateGetReturnsCorrectViewModel()
        {
            const int organizationId = 1;
            const int campaignId = 1;
            var campaignStartDateTime = DateTime.Now.AddDays(-1);
            var campaignEndDateTime = DateTime.Now.AddDays(1);

            var activity = new Activity
            {
                Id = 1,
                Name = "ActivityName",
                CampaignId = campaignId,
                Campaign = new Campaign
                {
                    Id = campaignId,
                    Name = "CampaignName",
                    ManagingOrganizationId = organizationId,
                    TimeZoneId = "EST",
                    StartDateTime = campaignStartDateTime,
                    EndDateTime = campaignEndDateTime
                }
            };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<ActivityByActivityIdQuery>())).Returns(activity);

            var sut = new TaskController(mediator.Object);
            MakeUserOrganizationAdminUser(sut, organizationId.ToString());

            var result = sut.Create(It.IsAny<int>()) as ViewResult;
            var modelResult = result.ViewData.Model as TaskEditModel;

            Assert.Equal(modelResult.ActivityId, activity.Id);
            Assert.Equal(modelResult.ActivityName, activity.Name);
            Assert.Equal(modelResult.CampaignId, activity.CampaignId);
            Assert.Equal(modelResult.CampaignName, activity.Campaign.Name);
            Assert.Equal(modelResult.OrganizationId, activity.Campaign.ManagingOrganizationId);
            Assert.Equal(modelResult.TimeZoneId, activity.Campaign.TimeZoneId);
            Assert.Equal(modelResult.StartDateTime, activity.StartDateTime);
            Assert.Equal(modelResult.EndDateTime, activity.EndDateTime);
        }
コード例 #13
0
 private bool UserIsOrganizationAdminOfActivity(Activity activity)
 {
     return User.IsOrganizationAdmin(activity.Campaign.ManagingOrganizationId);
 }
コード例 #14
0
 private bool UserIsTenantAdminOfActivity(Activity activity)
 {
     int? tenantId = User.GetTenantId();
     if (tenantId.HasValue)
     {
         Tenant tenant = _dataAccess.GetTenant(tenantId.Value);
         return User.IsUserType(UserType.SiteAdmin) || tenant.Campaigns.Any(c => c.Id == activity.CampaignId);
     } else
     {
         return false;
     }
 }
コード例 #15
0
        public async Task<IActionResult> Edit(Activity activity)
        {
            if (ModelState.IsValid)
            {
                await _dataAccess.UpdateActivity(activity);
                return RedirectToAction("Index");
            }

            return View(activity);
        }
コード例 #16
0
        public async Task PutCheckinSendsAddActivitySignupCommandAsyncWithCorrectDataWhenUsersSignedUpIsNotNullAndCheckinDateTimeIsNull()
        {
            const string userId = "userId";
            var utcNow = DateTime.UtcNow;

            var activity = new Activity();
            var activitySignup = new ActivitySignup { User = new ApplicationUser { Id = userId } };
            activity.UsersSignedUp.Add(activitySignup);

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<ActivityByActivityIdQuery>())).Returns(activity);

            var sut = new ActivityApiController(mediator.Object) { DateTimeUtcNow = () => utcNow }
                .SetFakeUser(userId);
            await sut.PutCheckin(It.IsAny<int>());

            mediator.Verify(x => x.SendAsync(It.Is<AddActivitySignupCommandAsync>(y => y.ActivitySignup == activitySignup)));
            mediator.Verify(x => x.SendAsync(It.Is<AddActivitySignupCommandAsync>(y => y.ActivitySignup.CheckinDateTime == utcNow)));
        }
コード例 #17
0
 Task IAllReadyDataAccess.UpdateActivity(Activity value)
 {
     _dbContext.Activities.Update(value);
       return _dbContext.SaveChangesAsync();
 }
コード例 #18
0
        public async Task<IActionResult> Edit(Activity activity)
        {
            var currentUser = await _userManager.GetCurrentUser(Context);
            if (currentUser == null)
            {
                return new HttpUnauthorizedResult();
            }

            if (ModelState.IsValid)
            {
                await _dataAccess.UpdateActivity(activity);
                return RedirectToAction("Index");
            }

            return View(activity);
        }
コード例 #19
0
        protected override void LoadTestData()
        {
            var context = ServiceProvider.GetService<AllReadyContext>();
            _user1 = new ApplicationUser
            {
                UserName = "******",
                Name = "John Doe",
                Email = "*****@*****.**"
            };
            _contact1 = new Contact
            {
                Id = 1,
                FirstName = "Jerry",
                LastName = "Rodgers",
                Email = "*****@*****.**",
                PhoneNumber = "555.555.1234"
            };

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

            _firePrev = new Campaign()
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = _htb,
                CampaignContacts = new List<CampaignContact>()
            };
            _firePrev.CampaignContacts.Add(new CampaignContact
            {
                Campaign = _firePrev,
                Contact = _contact1,
                ContactType = (int)ContactTypes.Primary
            });
            _htb.Campaigns.Add(_firePrev);
            _queenAnne = new Activity()
            {
                Id = 1,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = _firePrev,
                CampaignId = _firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<ActivitySkill>(),
                Tasks = new List<AllReadyTask>()
            };
            _queenAnne.UsersSignedUp = new List<ActivitySignup>
            {
                new ActivitySignup
                {
                    Id = 1,
                    PreferredEmail = "*****@*****.**",
                    PreferredPhoneNumber = "(555)555-1234",
                    User = _user1
                }
            };
            _task1 = new AllReadyTask()
            {
               Id = 1,
               Activity = _queenAnne,
               Name = "Task 1",
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Organization = _htb
            };
            _task1.AssignedVolunteers = new List<TaskSignup>()
            {
                new TaskSignup
                {
                    Id = 1,
                    User = _user1,
                    Task = _task1,
                    Status = "Assigned",
                    StatusDateTimeUtc = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime()
                }
            };
            _queenAnne.Tasks.Add(_task1);
            context.Users.Add(_user1);
            context.Contacts.Add(_contact1);
            context.Organizations.Add(_htb);
            context.Activities.Add(_queenAnne);
            context.SaveChanges();
        }
コード例 #20
0
ファイル: EditActivity.cs プロジェクト: mmoore99/allReady
        public void ExistingActivity()
        {
            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 Activity
            {
                Id = 100,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<ActivitySkill>()
            };
            context.Organizations.Add(htb);
            context.Activities.Add(queenAnne);
            context.SaveChanges();

            const string NEW_NAME = "Some new name value";

            var startDateTime = new DateTime(2015, 7, 12, 4, 15, 0);
            var endDateTime = new DateTime(2015, 12, 7, 15, 10, 0);
            var vm = new ActivityDetailModel
            {
                CampaignId = queenAnne.CampaignId,
                CampaignName = queenAnne.Campaign.Name,
                Description = queenAnne.Description,
                EndDateTime = endDateTime,
                Id = queenAnne.Id,
                ImageUrl = queenAnne.ImageUrl,
                Location = null,
                Name = NEW_NAME,
                RequiredSkills = queenAnne.RequiredSkills,
                TimeZoneId = "Central Standard Time",
                StartDateTime = startDateTime,
                Tasks = null,
                OrganizationId = queenAnne.Campaign.ManagingOrganizationId,
                OrganizationName = queenAnne.Campaign.ManagingOrganization.Name,
                Volunteers = null
            };
            var query = new EditActivityCommand { Activity = vm };
            var handler = new EditActivityCommandHandler(context);
            var result = handler.Handle(query);
            Assert.Equal(100, result); // should get back the activity id

            var data = context.Activities.Single(_ => _.Id == result);
            Assert.Equal(NEW_NAME, data.Name);

            Assert.Equal(2015, data.StartDateTime.Year);
            Assert.Equal(7, data.StartDateTime.Month);
            Assert.Equal(12, data.StartDateTime.Day);
            Assert.Equal(4, data.StartDateTime.Hour);
            Assert.Equal(15, data.StartDateTime.Minute);
            Assert.Equal(-5, data.StartDateTime.Offset.TotalHours);

            Assert.Equal(2015, data.EndDateTime.Year);
            Assert.Equal(12, data.EndDateTime.Month);
            Assert.Equal(7, data.EndDateTime.Day);
            Assert.Equal(15, data.EndDateTime.Hour);
            Assert.Equal(10, data.EndDateTime.Minute);
            Assert.Equal(-6, data.EndDateTime.Offset.TotalHours);
        }
コード例 #21
0
ファイル: EditActivity.cs プロジェクト: mmoore99/allReady
        public void ExistingActivityUpdateLocation()
        {
            PostalCodeGeo seattlePostalCode = new PostalCodeGeo() { City = "Seattle", PostalCode = "98117", State = "WA" };
            Location seattle = new Location()
            {
                Id = 1,
                Address1 = "123 Main Street",
                Address2 = "Unit 2",
                City = "Seattle",
                PostalCode = seattlePostalCode,
                Country = "USA",
                State = "WA",
                Name = "Organizer name",
                PhoneNumber = "555-555-5555"
            };

            var context = ServiceProvider.GetService<AllReadyContext>();
            Organization htb = new Organization()
            {
                Id = 123,
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };
            Campaign firePrev = new Campaign()
            {
                Id = 1,
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb,
                TimeZoneId = "Central Standard Time"
            };
            htb.Campaigns.Add(firePrev);
            Activity queenAnne = new Activity()
            {
                Id = 100,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = seattle,
                RequiredSkills = new List<ActivitySkill>()
            };
            context.Locations.Add(seattle);
            context.Organizations.Add(htb);
            context.Activities.Add(queenAnne);
            context.SaveChanges();

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

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

            var query = new EditActivityCommand { Activity = locationEdit };
            var handler = new EditActivityCommandHandler(context);
            var result = handler.Handle(query);
            Assert.Equal(100, result); // should get back the activity id

            var data = context.Activities.Single(a => a.Id == result);
            Assert.Equal(data.Location.Address1, NEW_LOCATION.Address1);
            Assert.Equal(data.Location.Address2, NEW_LOCATION.Address2);
            Assert.Equal(data.Location.City, NEW_LOCATION.City);
            Assert.Equal(data.Location.PostalCode?.PostalCode, NEW_LOCATION.PostalCode);
            Assert.Equal(data.Location.State, NEW_LOCATION.State);
            Assert.Equal(data.Location.Country, NEW_LOCATION.Country);
            Assert.Equal(data.Location.PhoneNumber, NEW_LOCATION.PhoneNumber);
            Assert.Equal(data.Location.Name, NEW_LOCATION.Name);
        }
コード例 #22
0
        public async Task PutCheckinReturnsCorrectJsonWhenUsersSignedUpIsNullAndCheckinDateTimeIsNotNull()
        {
            const string userId = "userId";
            var activity = new Activity { Name = "ActivityName", Description = "ActivityDescription" };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<ActivityByActivityIdQuery>())).Returns(activity);

            var sut = new ActivityApiController(mediator.Object)
                .SetFakeUser(userId);

            var expected = $"{{ NeedsSignup = True, Activity = {{ Name = {activity.Name}, Description = {activity.Description} }} }}";

            var result = (JsonResult)await sut.PutCheckin(It.IsAny<int>());

            Assert.IsType<JsonResult>(result);
            Assert.Equal(expected, result.Value.ToString());
        }
コード例 #23
0
        public async Task<IActionResult> Create(Activity activity)
        {
            var currentUser = await _userManager.GetCurrentUser(Context);
            if (activity.TenantId != _dataAccess.GetUser(currentUser.Id).AssociatedTenant.Id)
            {
                return new HttpUnauthorizedResult();
            }

            if (ModelState.IsValid)
            {
                await _dataAccess.AddActivity(activity);
                return RedirectToAction("Index");
            }
            return View(activity);
        }
コード例 #24
0
ファイル: TaskController.cs プロジェクト: fr33k3r/allReady
 private bool UserIsTenantAdminOfActivity(Activity activity)
 {
     return User.IsTenantAdmin(activity.Campaign.ManagingTenantId);
 }
コード例 #25
0
 private async Task<bool> UserIsTenantAdminOfActivity(ApplicationUser user, Activity activity)
 {
     return await _userManager.IsSiteAdmin(user) ||
         ((user.AssociatedTenant != null) &&
             (from campaign in user.AssociatedTenant.Campaigns
              where campaign.Id == activity.CampaignId
              select campaign).Any());
 }
コード例 #26
0
ファイル: TaskController.cs プロジェクト: BredStik/allReady
 private bool UserIsTenantAdminOfActivity(Activity activity)
 {
     return User.IsTenantAdmin(activity.TenantId);
 }
コード例 #27
0
ファイル: ActivityViewModel.cs プロジェクト: fr33k3r/allReady
        /// <summary>
        /// Returns null when there is no matching campaign for the campaign Id.
        /// </summary>
        public static Activity ToModel(this ActivityViewModel activity, IAllReadyDataAccess dataAccess)
        {
            var campaign = dataAccess.GetCampaign(activity.CampaignId);

            if (campaign == null)
                return null;

            Activity newActivity = new Activity()
            {
                Id = activity.Id,
                Campaign = campaign,
                EndDateTimeUtc = activity.EndDateTime.UtcDateTime,
                StartDateTimeUtc = activity.StartDateTime.UtcDateTime,
                Location = new Location()
                {
                    Address1 = activity.Location.Address1,
                    Address2 = activity.Location.Address2,
                    City = activity.Location.City,
                    Country = "US",
                    PostalCode = activity.Location.PostalCode,
                    State = activity.Location.State
                },
                Name = activity.Title
            };
            var tasks = new List<AllReadyTask>();

            foreach (TaskViewModel tvm in activity.Tasks)
            {
                tasks.Add(new AllReadyTask()
                {
                    Activity = newActivity,
                    Name = tvm.Name,
                    Id = tvm.Id,
                    Description = tvm.Description
                });
            }
            newActivity.Tasks = tasks;
            return newActivity;
        }
コード例 #28
0
 public ActivityViewModel(Activity activity, bool isUserSignedUp)
     : this(activity)
 {
     IsUserVolunteeredForActivity = isUserSignedUp.ToString().ToLowerInvariant();
 }
コード例 #29
0
ファイル: ActivityViewModel.cs プロジェクト: fr33k3r/allReady
 public static ActivityViewModel WithUserInfo(this ActivityViewModel viewModel, Activity activity, ClaimsPrincipal user, IAllReadyDataAccess dataAccess)
 {
     if (user.IsSignedIn())
     {
         var userId = user.GetUserId();
         var appUser = dataAccess.GetUser(userId);
         viewModel.UserId = userId;
         viewModel.UserSkills = appUser?.AssociatedSkills?.Select(us => us.Skill).ToList();
         viewModel.IsUserVolunteeredForActivity = dataAccess.GetActivitySignups(viewModel.Id, userId).Any();
         var assignedTasks = activity.Tasks.Where(t => t.AssignedVolunteers.Any(au => au.User.Id == userId)).ToList();
         viewModel.Tasks = new List<TaskViewModel>(assignedTasks.Select(data => new TaskViewModel(data, userId)).OrderBy(task => task.StartDateTime));
         viewModel.SignupModel = new ActivitySignupViewModel()
         {
             ActivityId = viewModel.Id,
             UserId = userId,
             Name = appUser.Name,
             PreferredEmail = appUser.Email,
             PreferredPhoneNumber = appUser.PhoneNumber
         };
     }
     else
     {
         viewModel.Tasks = new List<TaskViewModel>();
     }
     return viewModel;
 }
コード例 #30
0
        public async Task<IActionResult> Create(Activity activity)
        {            
            if (activity.TenantId != User.GetTenantId())
            {
                return new HttpUnauthorizedResult();
            }

            if (ModelState.IsValid)
            {
                await _dataAccess.AddActivity(activity);
                return RedirectToAction("Index");
            }
            return View(activity);
        }