Beispiel #1
0
        // GET: Activity/Details/5
        public async Task <IActionResult> Details(int id)
        {
            var activity = await Task.Run(() => _dataAccess.GetActivity(id));

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

            var avm = new AdminActivityViewModel
            {
                Id            = activity.Id,
                CampaignName  = activity.Campaign.Name,
                CampaignId    = activity.Campaign.Id,
                Title         = activity.Name,
                Description   = activity.Description,
                StartDateTime = activity.StartDateTimeUtc,
                EndDateTime   = activity.EndDateTimeUtc,
                Volunteers    = _dataAccess.ActivitySignups.Where(asup => asup.Activity.Id == id).Select(u => u.User.UserName).ToList(),
                Tasks         = activity.Tasks.Select(t => new TaskViewModel {
                    Name = t.Name
                }).OrderBy(t => t.StartDateTime).ThenBy(t => t.Name).ToList(),
                ImageUrl = activity.ImageUrl
            };

            return(View(avm));
        }
Beispiel #2
0
        public async Task <IActionResult> ShowActivity(int id)
        {
            var activity = _prepOpsDataAccess.GetActivity(id);

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

            var isUserSignedUpForActivity = User.IsSignedIn();

            if (!isUserSignedUpForActivity)
            {
                return(View("Activity", new ActivityViewModel(activity, false)));
            }

            var user = await GetCurrentUserAsync();

            var signedUp = _prepOpsDataAccess.GetActivitySignups(id, user);

            isUserSignedUpForActivity = signedUp.Any();

            return(View("Activity", new ActivityViewModel(activity, isUserSignedUpForActivity)));
        }
Beispiel #3
0
        public ActivityViewModel Get(int id)
        {
            var dbActivity = _prepOpsDataAccess.GetActivity(id);

            if (dbActivity != null)
            {
                return(new ActivityViewModel(dbActivity));
            }
            this.HttpNotFound();
            return(null);
        }
Beispiel #4
0
        public async Task<IActionResult> Index(int? activityId)
        {
            if (activityId != null)
            {
                ViewBag.ActivityId = activityId;
                return View(new List<Activity>() { _dataAccess.GetActivity((int)activityId) });
            }
            else
            {
                var currentUser = await _userManager.GetCurrentUser(Context);
                if (currentUser == null)
                {
                    return new HttpUnauthorizedResult();
                }
                var thisTenantsActivities = (from activity in _dataAccess.Activities
                                             where activity.Campaign.ManagingTenant == currentUser.AssociatedTenant
                                             select activity).ToList();

                return View(thisTenantsActivities);
            }
        }
Beispiel #5
0
        public static PrepOpsTask ToModel(this TaskViewModel task, IPrepOpsDataAccess dataAccess)
        {
            var activity = dataAccess.GetActivity(task.ActivityId);

            if (activity == null)
                return null;

            bool newTask = true;
            PrepOpsTask dbtask;

            if (task.Id == 0)
            {
                dbtask = new PrepOpsTask();
            }
            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;
        }
Beispiel #6
0
        public static PrepOpsTask ToModel(this TaskViewModel task, IPrepOpsDataAccess dataAccess)
        {
            var activity = dataAccess.GetActivity(task.ActivityId);

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

            bool        newTask = true;
            PrepOpsTask dbtask;

            if (task.Id == 0)
            {
                dbtask = new PrepOpsTask();
            }
            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);
        }