Пример #1
0
        public async virtual Task <ActionResult> Index()
        {
            var allBadges = await BadgeCollection.GetAllBadgesByTypeAsync(BadgeType.Unset);

            var allEarnedBadges = await EarnedBadgeCollection.GetAllBadgesForUserByTypeAsync(AuthenticatedUser.EmployeeId, BadgeType.Unset);

            var allActivities = await ActivityCollection.GetAllActivitiesAsync(true);

            var corporateBadges       = allBadges.Where(b => b.Type == BadgeType.Corporate);
            var communityBadges       = allBadges.Where(b => b.Type == BadgeType.Community);
            var earnedCorporateBadges = allEarnedBadges.Where(b => b.Type == BadgeType.Corporate);
            var earnedCommunityBadges = allEarnedBadges.Where(b => b.Type == BadgeType.Community);

            var sortedCorporateBadges = corporateBadges.OrderByDescending(b => b.BadgePriority);
            var sortedCommunityBadges = communityBadges.OrderByDescending(b => b.BadgePriority);
            var badgeIndexViewModel   = new BadgeIndexViewModel()
            {
                CorporateBadges       = sortedCorporateBadges,
                CorporateEarnedBadges = earnedCorporateBadges,
                CommunityBadges       = sortedCommunityBadges,
                CommunityEarnedBadges = earnedCommunityBadges,
                SubmittedActivity     = SubmitActivity.CreateActivitySubmission(AuthenticatedUser.EmployeeId),
                AvailableUsers        = await UserCollection.GetAllAvailabileUsersForCurrentUserAsync(),
            };

            badgeIndexViewModel.AllActivities      = allActivities;
            badgeIndexViewModel.PossibleActivities = allActivities.Select(ai => new SelectListItem()
            {
                Text = ai.Name, Value = ai.Id.ToString(CultureInfo.CurrentCulture)
            });

            return(View(badgeIndexViewModel));
        }
        /// <summary>
        /// Gets the minimum and optional maximum badge value.
        /// </summary>
        /// <param name="BadgeName">Name of the badge to get the value for.</param>
        /// <returns></returns>
        public async virtual Task <string> MaxAwardValue(string BadgeName)
        {
            var allActivities = await ActivityCollection.GetAllActivitiesAsync(false);

            var activityIds = allActivities.Where(x => x.Name == BadgeName).Select(x => x.Id);
            var allBadges   = await BadgeCollection.GetAllBadgesForActivitiesAsync(activityIds);

            var Badge       = allBadges.Select(x => new { x.Id, x.BadgeAwardValue, x.BadgeAwardValueMax }).FirstOrDefault();
            var valueObject = new { minval = Badge.BadgeAwardValue, maxval = Badge.BadgeAwardValueMax };

            return(Newtonsoft.Json.JsonConvert.SerializeObject(valueObject));;
        }
        public async virtual Task <ActionResult> AddBadge()
        {
            var allActivities = await ActivityCollection.GetAllActivitiesAsync(false);

            var badgeEdit          = BadgeEdit.CreateBadge();
            var badgeEditViewModel = new BadgeEditViewModel(allActivities);

            badgeEditViewModel.Badge          = badgeEdit as BadgeEdit;
            badgeEditViewModel.Badge.Priority = 0;

            return(View(Mvc.BadgeManager.Views.AddBadge, badgeEditViewModel));
        }
Пример #4
0
        public async virtual Task <ActionResult> SubmitActivityForm()
        {
            var submittedActivity = SubmitActivity.CreateActivitySubmission(AuthenticatedUser.EmployeeId);

            TryUpdateModel(submittedActivity, "SubmittedActivity");
            var activities = await ActivityCollection.GetAllActivitiesAsync(false);

            var badges = await BadgeCollection.GetAllBadgesForActivitiesAsync(activities.Where(x => x.Id == submittedActivity.ActivityId).Select(x => x.Id));

            var badge = badges.Select(x => new { x.Id, x.BadgeAwardValue, x.BadgeAwardValueMax }).FirstOrDefault();

            if (submittedActivity.AwardValue > badge.BadgeAwardValueMax || submittedActivity.AwardValue < badge.BadgeAwardValue)
            {
                ModelState.AddModelError("SubmittedActivity.AwardValue", String.Format("Award Value not within acceptable range. ({0} - {1})", badge.BadgeAwardValue, badge.BadgeAwardValueMax));
            }
            else if (string.IsNullOrWhiteSpace(submittedActivity.EmployeeIds))
            {
                ModelState.AddModelError("SubmittedActivity.EmployeeIds", ApplicationResources.NoEmployeeIdsErrorMsg);
            }
            else
            {
                //Parse the list of employee ids the client form sent us.
                List <int> empIds = submittedActivity.EmployeeIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                    .Convert(delegate(string item, out int result) { return(int.TryParse(item.Trim(), out result)); });

                bool allSaved = true;
                foreach (int empId in empIds)
                {
                    var singleActivity = SubmitActivity.CreateActivitySubmission(empId);
                    singleActivity.ActivityId             = submittedActivity.ActivityId;
                    singleActivity.ActivitySubmissionDate = submittedActivity.ActivitySubmissionDate;
                    singleActivity.Notes      = submittedActivity.Notes;
                    singleActivity.AwardValue = submittedActivity.AwardValue;

                    var singActEdit = await ActivityEdit.GetActivityEditByIdAsync(singleActivity.ActivityId);

                    singleActivity.EntryType = singActEdit.EntryType;
                    if (!await SaveObjectAsync(singleActivity, true))
                    {
                        allSaved = false;
                    }
                }

                if (allSaved)
                {
                    return(RedirectToAction(await Mvc.Activities.Actions.Index()));
                }
            }

            return(await Index());
        }
        public virtual async Task <ActionResult> Compare(string userName)
        {
            var leftLeaderboardItem = await LeaderboardItem.GetLeaderboardForUserName(AuthenticatedUser.UserName);

            var rightLeaderboardItem = await LeaderboardItem.GetLeaderboardForUserName(userName);

            var allBadges = await BadgeCollection.GetAllBadgesByTypeAsync(BadgeType.Unset);

            var allActivities = await ActivityCollection.GetAllActivitiesAsync(false);

            var leaderboardCompareViewModel = new LeaderboardCompareViewModel();

            leaderboardCompareViewModel.LeftLeaderboardItem  = leftLeaderboardItem;
            leaderboardCompareViewModel.RightLeaderboardItem = rightLeaderboardItem;
            leaderboardCompareViewModel.AllBadges            = allBadges;
            leaderboardCompareViewModel.AllActivities        = allActivities;

            return(View(leaderboardCompareViewModel));
        }
        public virtual async Task <ActionResult> EditBadge(int id)
        {
            var allActivities = await ActivityCollection.GetAllActivitiesAsync(false);

            var badgeEdit = await BadgeEdit.GetBadgeEditByIdAsync(id);

            if (BusinessRules.HasPermission(AuthorizationActions.EditObject, badgeEdit))
            {
                var badgeEditViewModel = new BadgeEditViewModel(allActivities, badgeEdit.BadgeActivities);
                badgeEditViewModel.Badge = badgeEdit as BadgeEdit;
                if (badgeEditViewModel.Badge.Priority == Int32.MaxValue)
                {
                    badgeEditViewModel.Badge.Priority = 0;
                }

                return(View(Mvc.BadgeManager.Views.EditBadge, badgeEditViewModel));
            }

            return(RedirectToAction(Mvc.Error.AccessDenied()));
        }
Пример #7
0
        public async virtual Task <ActionResult> Index()
        {
            var submittedActivities = await SubmittedActivityCollection.GetSubmittedActivitiesByEmployeeIdAsync(AuthenticatedUser.EmployeeId, null, null);

            var activityIndexViewModel = new ActivityIndexViewModel()
            {
                SubmittedActivity = SubmitActivity.CreateActivitySubmission(AuthenticatedUser.EmployeeId),
                AvailableUsers    = await UserCollection.GetAllAvailabileUsersForCurrentUserAsync(),
            };

            var allActivities = await ActivityCollection.GetAllActivitiesAsync(true);

            activityIndexViewModel.PossibleActivities = allActivities.Select(ai => new SelectListItem()
            {
                Text = ai.Name, Value = ai.Id.ToString(CultureInfo.CurrentCulture)
            });
            activityIndexViewModel.PreviousActivities = await SubmittedActivityCollection.GetSubmittedActivitiesByEmployeeIdAsync(AuthenticatedUser.EmployeeId, null, null);

            return(View(Mvc.Activities.Views.Index, activityIndexViewModel));
        }