예제 #1
0
        public ActivityViewModel(Activity activity)
        {
            Id = activity.Id;
            if (activity.Campaign != null)
            {
                CampaignId = activity.Campaign.Id;
                CampaignName = activity.Campaign.Name;
            }

            if (activity.Tenant != null)
            {
                TenantId = activity.Tenant.Id;
                TenantName = activity.Tenant.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>();
        }
예제 #2
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());
 }
예제 #3
0
        public async Task<IActionResult> Edit(Activity activity)
        {
            var currentUser = await _userManager.GetCurrentUser(Context);
            if (currentUser == null || !await _userManager.IsTenantAdmin(currentUser))
            {
                return new HttpUnauthorizedResult();
            }

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

            return View(activity);
        }
예제 #4
0
 Task IPrepOpsDataAccess.UpdateActivity(Activity value)
 {
     _dbContext.Activities.Update(value);
     return _dbContext.SaveChangesAsync();
 }
예제 #5
0
 public ActivityViewModel(Activity activity, bool isUserSignedUp)
     : this(activity)
 {
     IsUserVolunteeredForActivity = isUserSignedUp.ToString().ToLowerInvariant();
 }
예제 #6
0
        /// <summary>
        /// Returns null when there is no matching campaign for the campaign Id.
        /// </summary>
        public static Activity ToModel(this ActivityViewModel activity, IPrepOpsDataAccess 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<PrepOpsTask>();
            foreach (TaskViewModel tvm in activity.Tasks)
            {
                tasks.Add(new PrepOpsTask()
                {
                    Activity = newActivity,
                    Name = tvm.Name,
                    Id = tvm.Id,
                    Description = tvm.Description
                });
            }
            newActivity.Tasks = tasks;
            return newActivity;
        }