Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        public async Task<IActionResult> Assign(int id)
        {
            var currentUser = await _userManager.GetCurrentUser(Context);
            if (currentUser == null)
            {
                return new HttpUnauthorizedResult();
            }

            var activity = _dataAccess.GetActivity(id);

            if (activity == null)
            {
                return new HttpStatusCodeResult(404);
            }
            if (!await UserIsTenantAdminOfActivity(currentUser, activity))
            {
                return new HttpUnauthorizedResult();
            }

            var model = new ActivityViewModel(activity);
            model.Tasks = model.Tasks.OrderBy(t => t.StartDateTime).ThenBy(t => t.Name).ToList();
            model.Volunteers = activity.UsersSignedUp.Select(u => u.User).ToList();

            return View(model);
        }
Ejemplo n.º 3
0
        public IActionResult Assign(int id)
        {
            //TODO: Update this to use Query pattern
            var activity = _dataAccess.GetActivity(id);

            if (activity == null)
            {
                return HttpNotFound();
            }
            if (!User.IsOrganizationAdmin(activity.Campaign.ManagingOrganizationId))
            {
                return HttpUnauthorized();
            }

            var model = new ActivityViewModel(activity);
            model.Tasks = model.Tasks.OrderBy(t => t.StartDateTime).ThenBy(t => t.Name).ToList();
            model.Volunteers = activity.UsersSignedUp.Select(u => u.User).ToList();

            return View(model);
        }
        public void PostSingleActivity()
        {
            // Arrange
            ActivityApiController controller = GetActivityController();

            //Act
            ActivityViewModel toPost = new ActivityViewModel()
            {
                Id = 11,
                Title = "the answer to life the universe and everything",
                CampaignId = 1,
                TenantId = 1,
                StartDateTime = DateTime.Today,
                EndDateTime = DateTime.Today.AddMonths(1),
                Location = new LocationViewModel()
                {
                    Address1 = "123 Happy Street",
                    City = "Madison",
                    State = "WI",
                    PostalCode = new PostalCodeGeo() { PostalCode = "53711" },
                    Country = "country gets ignored right now"
                }
            };

            controller.Post(toPost);
            activitiesAdded++;
            var viewModelFromDb = controller.Get(toPost.Id);

            // Assert
            Assert.NotEqual(viewModelFromDb, toPost);
            Assert.Equal(toPost.Id, viewModelFromDb.Id);
            Assert.Equal(toPost.CampaignId, viewModelFromDb.CampaignId);
            Assert.Equal(string.Format(TestActivityModelProvider.CampaignNameFormat, toPost.CampaignId), viewModelFromDb.CampaignName);
            Assert.Null(viewModelFromDb.Description);
            Assert.Equal(toPost.EndDateTime, viewModelFromDb.EndDateTime);
            Assert.Equal(toPost.StartDateTime, viewModelFromDb.StartDateTime);
            Assert.Equal("US", viewModelFromDb.Location.Country);
            Assert.Equal(toPost.Location.Address1, viewModelFromDb.Location.Address1);
            Assert.Equal(toPost.Location.City, viewModelFromDb.Location.City);
        }
Ejemplo n.º 5
0
        public IActionResult Assign(int id)
        {
            var activity = _dataAccess.GetActivity(id);

            if (activity == null)
            {
                return new HttpStatusCodeResult(404);
            }
            if (!UserIsTenantAdminOfActivity(activity))
            {
                return new HttpUnauthorizedResult();
            }

            var model = new ActivityViewModel(activity);
            model.Tasks = model.Tasks.OrderBy(t => t.StartDateTime).ThenBy(t => t.Name).ToList();
            model.Volunteers = activity.UsersSignedUp.Select(u => u.User).ToList();

            return View(model);
        }