Esempio n. 1
0
 private BadgeAwardDTO CreateNewBadgeAward(ActivityInfoDTO activity, BadgeEditDTO potentialBadge)
 {
     return new BadgeAwardDTO
     {
         BadgeId = potentialBadge.Id,
         AwardAmount = potentialBadge.AwardValueAmount,
         EmployeeId = activity.EmployeeId,
         AwardDate = DateTime.UtcNow
     };
 }
        public async Task<IEnumerable<ApproveActivityItemDTO>> GetActivitiesToApproveForManagerAsync(IApproveActivityCollectionCriteria criteria)
        {
            using (var ctx = new Entities())
            {
                ctx.Database.Connection.Open();
                var activityList = await (from t in ctx.ActivitySubmissions
                                          join e in ctx.Employees on t.EmployeeId equals e.EmployeeId
                                          join a in ctx.Activities on t.ActivityId equals a.ActivityId
                                          where t.SubmissionStatusId == (int)ActivitySubmissionStatus.AwaitingApproval
                                          where (e.ApprovingManagerId1 == criteria.ManagerEmployeeId
                                          || e.ApprovingManagerId2 == criteria.ManagerEmployeeId)
                                          select new ApproveActivityItemDTO
                                          {
                                              SubmissionId = t.ActivitySubmissionId,
                                              SubmissionDate = t.SubmissionDate,
                                              ActivityId = t.ActivityId,
                                              ActivityDescription = a.ActivityDescription,
                                              ActivityName = a.ActivityName,
                                              ApprovedById = t.SubmissionApprovedById ?? 0,
                                              EmployeeId = t.EmployeeId,
                                              EmployeeADName = e.ADName,
                                              EmployeeFirstName = e.FirstName,
                                              EmployeeLastName = e.LastName,
                                              Status = (ActivitySubmissionStatus)t.SubmissionStatusId,
                                              SubmissionNotes = t.SubmissionDescription
                                          }).ToArrayAsync();

                foreach (var activity in activityList)
                {
                    var activityInfo = new ActivityInfoDTO
                    {
                        EmployeeId = activity.EmployeeId,
                        ActivityId = activity.ActivityId,
                        Status = ActivitySubmissionStatus.Approved
                    };
                    var badgeIds = criteria.AwardBadges.CreateBadges(activityInfo).Select(b => b.BadgeId).ToArray();

                    activity.ApproveActivityBadgeItemCollection = await (from t in ctx.Badges
                                                                         where badgeIds.Contains(t.BadgeId)
                                                                         select new ApproveActivityBadgeItemDTO
                                                                         {
                                                                             BadgeId = t.BadgeId,
                                                                             Name = t.BadgeName,
                                                                             Type = (Common.Enums.BadgeType)t.BadgeTypeId,
                                                                             ImagePath = t.BadgePath,
                                                                             BadgePriority = t.BadgePriority,
                                                                             AwardValueAmount = t.BadgeAwardValueAmount
                                                                         }).ToArrayAsync();
                }

                return activityList;
            }
        }
Esempio n. 3
0
        public IQueryable<BadgeAwardDTO> CreateBadges(ActivityInfoDTO activityInfo)
        {
            var activityDal = IoC.Container.Resolve<IBadgeEditDAL>();
            var potentialBadges = activityDal.GetPotentialBadgesForActivity(activityInfo.ActivityId);
            var dal = IoC.Container.Resolve<IAwardBadgesDAL>();
            var earnedBadges = dal.GetAwardedBadgesForUser(activityInfo.EmployeeId);
            var previousActivities = dal.GetPreviousActivitiesForUser(activityInfo.EmployeeId, activityInfo.ActivityId);

            var returnBadges = GetBadgeAwardsForActivity(activityInfo, potentialBadges, earnedBadges, previousActivities,
                DateTime.UtcNow);
            activityInfo.Status = ActivitySubmissionStatus.Complete;

            return returnBadges;
        }
Esempio n. 4
0
        public IQueryable<BadgeAwardDTO> GetBadgeAwardsForActivity(ActivityInfoDTO activityInfo,
            IList<BadgeEditDTO> potentialBadges, IList<BadgeAwardDTO> earnedBadges,
            IList<SubmittedActivityItemDTO> previousActivities, DateTime activityApprovalTime)
        {
            var returnValue = new List<BadgeAwardDTO>();

            if (activityInfo.Status == ActivitySubmissionStatus.Approved)
            {
                foreach (var potentialBadge in potentialBadges)
                {
                    if (potentialBadge.BadgeActivities.Any(ba => ba.ActivityId == activityInfo.ActivityId)
                        & AllowedToBeAwarded(potentialBadge, earnedBadges)
                        & BadgeValidForDate(activityApprovalTime, potentialBadge)
                        & potentialBadge.BadgeStatus == BadgeStatus.Approved
                        & CorrectNumberOfEarnedBadges(activityInfo.ActivityId, potentialBadge, previousActivities))
                    {
                        returnValue.Add(CreateNewBadgeAward(activityInfo, potentialBadge));
                    }
                }
            }

            return returnValue.AsQueryable();
        }
        public void AllTogetherMultiplePotentialBadgesAwardsMultipleBadges()
        {
            var targetActivityId = 1;
            var activityInfo = new ActivityInfoDTO
            {
                ActivityId = targetActivityId,
                Status = ActivitySubmissionStatus.Approved,
                EmployeeId = 4
            };
            var potentialBadges = new List<BadgeEditDTO>();
            potentialBadges.Add(new BadgeEditDTO
            {
                Id = 1,
                MultipleAwardsPossible = true,
                EffectiveStartDate = DateTime.Parse("1/1/2013", CultureInfo.CurrentCulture),
                EffectiveEndDate = DateTime.Parse("1/1/2015", CultureInfo.CurrentCulture),
                ApprovedById = 1,
                ActivityPointsAmount = 1,
                BadgeStatus = BadgeStatus.Approved,
                BadgeActivities = new List<BadgeActivityEditDTO> { new BadgeActivityEditDTO { ActivityId = targetActivityId } }
            });
            potentialBadges.Add(new BadgeEditDTO
            {
                Id = 2,
                MultipleAwardsPossible = true,
                EffectiveStartDate = DateTime.Parse("1/1/2013", CultureInfo.CurrentCulture),
                EffectiveEndDate = DateTime.Parse("1/1/2015", CultureInfo.CurrentCulture),
                ApprovedById = 1,
                ActivityPointsAmount = 1,
                BadgeStatus = BadgeStatus.Approved,
                BadgeActivities = new List<BadgeActivityEditDTO> { new BadgeActivityEditDTO { ActivityId = targetActivityId } }
            });

            var earnedBadges = new List<BadgeAwardDTO>();
            var previousActivities = new List<SubmittedActivityItemDTO>();

            var awardBadges = new AwardBadges();
            var result = awardBadges.GetBadgeAwardsForActivity(activityInfo, potentialBadges, earnedBadges, previousActivities, DateTime.Parse("1/1/2014", CultureInfo.CurrentCulture));

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count());
        }