コード例 #1
0
        public ActivityViewModel Get(int id)
        {
            var dbActivity = _allReadyDataAccess.GetActivity(id);

            if (dbActivity != null)
            {
                return(new ActivityViewModel(dbActivity));
            }
            this.HttpNotFound();
            return(null);
        }
コード例 #2
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));
            }
        }
コード例 #3
0
        public IActionResult ShowActivity(int id)
        {
            var activity = _allReadyDataAccess.GetActivity(id);

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

            return(View("Activity", new ActivityViewModel(activity).WithUserInfo(activity, User, _allReadyDataAccess)));
        }
コード例 #4
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));
        }
コード例 #5
0
        public ActivityViewModel Handle(ShowActivityQuery message)
        {
            var activity = _dataAccess.GetActivity(message.ActivityId);

            if (activity == null || activity.Campaign.Locked)
            {
                return(null);
            }

            return(new ActivityViewModel(activity)
                   .WithUserInfo(activity, message.User, _dataAccess));
        }
コード例 #6
0
        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
                {
                    Id          = t.Id,
                    ActivityId  = id,
                    Name        = t.Name,
                    Description = t.Description
                })
                                .OrderBy(t => t.StartDateTime).ThenBy(t => t.Name).ToList(),
                ImageUrl = activity.ImageUrl
            };

            return(View(avm));
        }
コード例 #7
0
ファイル: TaskController.cs プロジェクト: weiplanet/allReady
        public IActionResult Create(int activityId)
        {
            var activity = _dataAccess.GetActivity(activityId);

            if (activity == null || !User.IsOrganizationAdmin(activity.Campaign.ManagingOrganizationId))
            {
                return(HttpUnauthorized());
            }
            var viewModel = new TaskEditModel()
            {
                ActivityId     = activity.Id,
                ActivityName   = activity.Name,
                CampaignId     = activity.CampaignId,
                CampaignName   = activity.Campaign.Name,
                OrganizationId = activity.Campaign.ManagingOrganizationId,
                TimeZoneId     = activity.Campaign.TimeZoneId,
                StartDateTime  = activity.StartDateTime,
                EndDateTime    = activity.EndDateTime,
            };

            return(View("Edit", viewModel));
        }
コード例 #8
0
        public IActionResult ShowActivity(int id)
        {
            var activity = _allReadyDataAccess.GetActivity(id);

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

            var isUserSignedUpForActivity = User.IsSignedIn();

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

            var signedUp = _allReadyDataAccess.GetActivitySignups(id, User.GetUserId());

            isUserSignedUpForActivity = signedUp.Any();

            return(View("Activity", new ActivityViewModel(activity, isUserSignedUpForActivity)));
        }
コード例 #9
0
        public async Task <IActionResult> ShowActivity(int id)
        {
            var activity = _allReadyDataAccess.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 = _allReadyDataAccess.GetActivitySignups(id, user);

            isUserSignedUpForActivity = signedUp.Any();

            return(View("Activity", new ActivityViewModel(activity, isUserSignedUpForActivity)));
        }
コード例 #10
0
        public IActionResult Index(int?activityId)
        {
            if (activityId != null)
            {
                ViewBag.ActivityId = activityId;
                return(View(new List <Activity>()
                {
                    _dataAccess.GetActivity((int)activityId)
                }));
            }
            else
            {
                var tenantId = User.GetTenantId();
                var thisTenantsActivities = (from activity in _dataAccess.Activities
                                             where activity.Campaign.ManagingTenantId == tenantId
                                             select activity).ToList();

                return(View(thisTenantsActivities));
            }
        }
コード例 #11
0
ファイル: TaskViewModel.cs プロジェクト: mmoore99/allReady
        public static AllReadyTask ToModel(this TaskViewModel taskViewModel, IAllReadyDataAccess dataAccess)
        {
            var activity = dataAccess.GetActivity(taskViewModel.ActivityId);

            if (activity == null)
                return null;

            bool newTask = true;
            AllReadyTask dbtask;

            if (taskViewModel.Id == 0)
            {
                dbtask = new AllReadyTask();
            }
            else
            {
                dbtask = dataAccess.GetTask(taskViewModel.Id);
                newTask = false;
            }

            dbtask.Id = taskViewModel.Id;
            dbtask.Description = taskViewModel.Description;
            dbtask.Activity = activity;
            dbtask.EndDateTime = taskViewModel.EndDateTime.HasValue ? taskViewModel.EndDateTime.Value.UtcDateTime : new Nullable<DateTime>();
            dbtask.StartDateTime = taskViewModel.EndDateTime.HasValue ? taskViewModel.StartDateTime.Value.UtcDateTime : new Nullable<DateTime>();
            dbtask.Name = taskViewModel.Name;
            dbtask.RequiredSkills = dbtask.RequiredSkills ?? new List<TaskSkill>();
            taskViewModel.RequiredSkills = taskViewModel.RequiredSkills ?? new List<int>();
            ////Remove old skills
            //dbtask.RequiredSkills.RemoveAll(ts => !taskViewModel.RequiredSkills.Any(s => ts.SkillId == s));
            ////Add new skills
            //dbtask.RequiredSkills.AddRange(taskViewModel.RequiredSkills
            //    .Where(rs => !dbtask.RequiredSkills.Any(ts => ts.SkillId == rs))
            //    .Select(rs => new TaskSkill() { SkillId = rs, TaskId = taskViewModel.Id }));

            // 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 (taskViewModel.AssignedVolunteers != null)
            {
                var bogusAssignedVolunteers = (from assignedVolunteer in taskViewModel.AssignedVolunteers
                                               where string.IsNullOrEmpty(assignedVolunteer.UserId)
                                               select assignedVolunteer).ToList();
                foreach (var bogus in bogusAssignedVolunteers)
                {
                    taskViewModel.AssignedVolunteers.Remove(bogus);
                }
            }
            // end workaround


            if (taskViewModel.AssignedVolunteers != null && taskViewModel.AssignedVolunteers.Count > 0)
            {
                var taskUsersList = taskViewModel.AssignedVolunteers.Select(tvm => new TaskSignup
                {
                    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 (TaskSignup 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;

        }
コード例 #12
0
        public static AllReadyTask ToModel(this TaskViewModel taskViewModel, IAllReadyDataAccess dataAccess)
        {
            var activity = dataAccess.GetActivity(taskViewModel.ActivityId);

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

            bool         newTask = true;
            AllReadyTask dbtask;

            if (taskViewModel.Id == 0)
            {
                dbtask = new AllReadyTask();
            }
            else
            {
                dbtask  = dataAccess.GetTask(taskViewModel.Id);
                newTask = false;
            }

            dbtask.Id                    = taskViewModel.Id;
            dbtask.Description           = taskViewModel.Description;
            dbtask.Activity              = activity;
            dbtask.EndDateTime           = taskViewModel.EndDateTime.HasValue ? taskViewModel.EndDateTime.Value.UtcDateTime : new Nullable <DateTime>();
            dbtask.StartDateTime         = taskViewModel.EndDateTime.HasValue ? taskViewModel.StartDateTime.Value.UtcDateTime : new Nullable <DateTime>();
            dbtask.Name                  = taskViewModel.Name;
            dbtask.RequiredSkills        = dbtask.RequiredSkills ?? new List <TaskSkill>();
            taskViewModel.RequiredSkills = taskViewModel.RequiredSkills ?? new List <int>();
            ////Remove old skills
            //dbtask.RequiredSkills.RemoveAll(ts => !taskViewModel.RequiredSkills.Any(s => ts.SkillId == s));
            ////Add new skills
            //dbtask.RequiredSkills.AddRange(taskViewModel.RequiredSkills
            //    .Where(rs => !dbtask.RequiredSkills.Any(ts => ts.SkillId == rs))
            //    .Select(rs => new TaskSkill() { SkillId = rs, TaskId = taskViewModel.Id }));

            // 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 (taskViewModel.AssignedVolunteers != null)
            {
                var bogusAssignedVolunteers = (from assignedVolunteer in taskViewModel.AssignedVolunteers
                                               where string.IsNullOrEmpty(assignedVolunteer.UserId)
                                               select assignedVolunteer).ToList();
                foreach (var bogus in bogusAssignedVolunteers)
                {
                    taskViewModel.AssignedVolunteers.Remove(bogus);
                }
            }
            // end workaround


            if (taskViewModel.AssignedVolunteers != null && taskViewModel.AssignedVolunteers.Count > 0)
            {
                var taskUsersList = taskViewModel.AssignedVolunteers.Select(tvm => new TaskSignup
                {
                    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 (TaskSignup 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);
        }
コード例 #13
0
 public Models.Activity Handle(ActivityByActivityIdQuery message)
 {
     return(dataAccess.GetActivity(message.ActivityId));
 }