Ejemplo n.º 1
0
 private BadgeEditDTO LoadReturnData(Badge badge)
 {
     var returnValue = new BadgeEditDTO
     {
         Id = badge.BadgeId,
         Name = badge.BadgeName,
         Tagline = badge.BadgeTagLine,
         Description = badge.BadgeDescription,
         Type = (Common.Enums.BadgeType)badge.BadgeTypeId,
         ImagePath = badge.BadgePath,
         Created = badge.BadgeCreated,
         EffectiveStartDate = badge.BadgeEffectiveStart,
         EffectiveEndDate = badge.BadgeEffectiveEnd,
         Priority = badge.BadgePriority,
         MultipleAwardsPossible = badge.MultipleAwardPossible,
         DisplayOnce = badge.DisplayOnce,
         ManagementApprovalRequired = badge.ManagementApprovalRequired,
         ActivityPointsAmount = badge.ActivityPointsAmount,
         AwardValueAmount = badge.BadgeAwardValueAmount,
         ApprovedById = badge.BadgeApprovedById ?? 0,
         ApprovedDate = badge.BadgeApprovedDate,
         BadgeStatus = (Common.Enums.BadgeStatus)badge.BadgeStatusId,
         CreateEmployeeId = badge.CreateEmployeeId,
         BadgeActivities = new List<BadgeActivityEditDTO>()
     };
     foreach (var badgeActivity in badge.BadgeActivities)
     {
         returnValue.BadgeActivities.Add(new BadgeActivityEditDTO
         {
             BadgeActivityId = badgeActivity.BadgeActivityId,
             ActivityId = badgeActivity.ActivityId
         });
     }
     return returnValue;
 }
Ejemplo n.º 2
0
 public static bool BadgeValidForDate(DateTime activityApprovalTime, BadgeEditDTO potentialBadge)
 {
     var returnValue = (!potentialBadge.EffectiveStartDate.HasValue
             || potentialBadge.EffectiveStartDate.Value <= activityApprovalTime)
            && (!potentialBadge.EffectiveEndDate.HasValue
                || potentialBadge.EffectiveEndDate.Value >= activityApprovalTime);
     return returnValue;
 }
Ejemplo n.º 3
0
 public Task<BadgeEditDTO> GetBadgeByIdAsync(int badgeEditId)
 {
     var dto = new BadgeEditDTO
     {
         Id = 1,
         ImagePath = ImagePath
     };
     dto.BadgeActivities = new List<BadgeActivityEditDTO>();
     return Task.FromResult(dto);
 }
Ejemplo n.º 4
0
 private static BadgeAwardDTO CreateNewBadgeAward(ActivityInfo activity, BadgeEditDTO potentialBadge)
 {
     return new BadgeAwardDTO
     {
         BadgeId = potentialBadge.Id,
         AwardAmount = potentialBadge.AwardValueAmount,
         EmployeeId = activity.EmployeeId,
         AwardDate = DateTime.UtcNow
     };
 }
Ejemplo n.º 5
0
        public static bool CorrectNumberOfEarnedBadges(int activityId, BadgeEditDTO potentialBadge, IList<SubmittedActivityItemDTO> previousActivities)
        {
            var returnValue = false;
            if (potentialBadge.ActivityPointsAmount != 0)
            {
                returnValue = ((previousActivities.Count(pa => pa.Status == ActivitySubmissionStatus.Complete
                                                         && pa.ActivityId == activityId) + 1) %
                         potentialBadge.ActivityPointsAmount == 0);
            }

            return returnValue;
        }
Ejemplo n.º 6
0
        public void NotAllowedOutsideDateRange()
        {
            var approvalDate = DateTime.Parse("1/1/2012", CultureInfo.CurrentCulture);
            var dto = new BadgeEditDTO
            {
                EffectiveStartDate = DateTime.Parse("1/1/2013", CultureInfo.CurrentCulture),
                EffectiveEndDate = DateTime.Parse("1/1/2015", CultureInfo.CurrentCulture)
            };

            var result = AwardBadges.BadgeValidForDate(approvalDate, dto);

            Assert.IsFalse(result);
        }
Ejemplo n.º 7
0
        public void AllowedNeverAwarded()
        {
            var dto = new BadgeEditDTO
            {
                Id = 1,
                MultipleAwardsPossible = false
            };
            var earnedBadges = new List<BadgeAwardDTO>();

            var result = AwardBadges.AllowedToBeAwarded(dto, earnedBadges);

            Assert.IsTrue(result);
        }
Ejemplo n.º 8
0
        public void NotAllowedWithMultipleBadges()
        {
            var dto = new BadgeEditDTO
            {
                Id = 1,
                MultipleAwardsPossible = false
            };
            var earnedBadges = new List<BadgeAwardDTO>();
            earnedBadges.Add(new BadgeAwardDTO { BadgeId = 1 });

            var result = AwardBadges.AllowedToBeAwarded(dto, earnedBadges);

            Assert.IsFalse(result);
        }
Ejemplo n.º 9
0
        public BadgeEditDTO Update(BadgeEditDTO data)
        {
            using (var ctx = new Entities())
            {
                ctx.Database.Connection.Open();
                var saveBadge = LoadData(data);
                ctx.Badges.Attach(saveBadge);
                var objectState = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager;
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgeName");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgeTagLine");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgeDescription");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgeTypeId");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgePath");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgeCreated");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgeEffectiveStart");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgeEffectiveEnd");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgePriority");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("MultipleAwardPossible");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("DisplayOnce");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("ManagementApprovalRequired");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("ActivityPointsAmount");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgeAwardValueAmount");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgeApprovedById");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgeApprovedDate");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgeStatusId");
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("CreateEmployeeId");

                AttachChildren(ctx, data, saveBadge.BadgeId);
                ctx.SaveChanges();

                data.Id = saveBadge.BadgeId;
                this.SaveToBlobStorage(data);
                saveBadge.BadgePath = data.ImagePath;
                objectState = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager;
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgePath");
                ctx.SaveChanges();

                var badge = GetRefreshedBadgeInfo(ctx, saveBadge.BadgeId);
                data = LoadReturnData(badge);
            }

            return data;
        }
Ejemplo n.º 10
0
        public void NotAllowedTwoPreviousTwoRequired()
        {
            var dto = new BadgeEditDTO
            {
                ActivityPointsAmount = 2
            };
            var previousActivities = new List<SubmittedActivityItemDTO>();
            previousActivities.Add(new SubmittedActivityItemDTO
            {
                ActivityId = 1,
                Status = ActivitySubmissionStatus.Complete
            });
            previousActivities.Add(new SubmittedActivityItemDTO
            {
                ActivityId = 1,
                Status = ActivitySubmissionStatus.Complete
            });

            var result = AwardBadges.CorrectNumberOfEarnedBadges(1, dto, previousActivities);

            Assert.IsFalse(result);
        }
Ejemplo n.º 11
0
        public void AllowedNoPreviousOneRequired()
        {
            var dto = new BadgeEditDTO
            {
                ActivityPointsAmount = 1
            };
            var previousActivities = new List<SubmittedActivityItemDTO>();

            var result = AwardBadges.CorrectNumberOfEarnedBadges(1, dto, previousActivities);

            Assert.IsTrue(result);
        }
Ejemplo n.º 12
0
        public BadgeEditDTO Insert(BadgeEditDTO data)
        {
            using (var ctx = new Entities())
            {
                ctx.Database.Connection.Open();
                var saveBadge = LoadData(data);
                ctx.Badges.Add(saveBadge);

                ctx.SaveChanges();
                AttachChildren(ctx, data, saveBadge.BadgeId);
                ctx.SaveChanges();

                data.Id = saveBadge.BadgeId;
                this.SaveToBlobStorage(data);
                saveBadge.BadgePath = data.ImagePath;
                var objectState = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager;
                objectState.GetObjectStateEntry(saveBadge).SetModifiedProperty("BadgePath");
                ctx.SaveChanges();

                var badge = GetRefreshedBadgeInfo(ctx, saveBadge.BadgeId);
                data = LoadReturnData(badge);
            }


            return data;
        }
Ejemplo n.º 13
0
 private void AttachChildren(Entities ctx, BadgeEditDTO data, int badgeId)
 {
     foreach (var badgeActivity in data.BadgeActivities)
     {
         if (badgeActivity.IsDeleted && badgeActivity.BadgeActivityId > 0) // Delete
         {
             var deleteBadgeActivity = new BadgeActivity
             {
                 BadgeActivityId = badgeActivity.BadgeActivityId
             };
             ctx.BadgeActivities.Attach(deleteBadgeActivity);
             ctx.BadgeActivities.Remove(deleteBadgeActivity);
         }
         else if (!badgeActivity.IsDeleted && badgeActivity.BadgeActivityId == 0) // Insert
         {
             var insertBadgeActivity = new BadgeActivity
             {
                 ActivityId = badgeActivity.ActivityId,
                 BadgeId = badgeId
             };
             ctx.BadgeActivities.Add(insertBadgeActivity);
         }
         else if (!badgeActivity.IsDeleted && badgeActivity.BadgeActivityId > 0) // Update
         {
             var updateBadgeActivity = new BadgeActivity
             {
                 BadgeActivityId = badgeActivity.BadgeActivityId,
                 ActivityId = badgeActivity.ActivityId,
                 BadgeId = badgeId
             };
             ctx.BadgeActivities.Attach(updateBadgeActivity);
             var objectState = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager;
             objectState.GetObjectStateEntry(updateBadgeActivity).SetModifiedProperty("ActivityId");
             objectState.GetObjectStateEntry(updateBadgeActivity).SetModifiedProperty("BadgeId");
         }
     }
 }
Ejemplo n.º 14
0
 public BadgeEditDTO Insert(BadgeEditDTO data)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 15
0
 public BadgeEditDTO Update(BadgeEditDTO data)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
        private void SaveToBlobStorage(BadgeEditDTO data)
        {
            if (data.BadgeImage != null && data.BadgeImage.Length > 0)
            {
                var storageAccount =
                    CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageAccountConnectionString"]);

                var blobClient = storageAccount.CreateCloudBlobClient();
                var container = blobClient.GetContainerReference(ConfigurationManager.AppSettings["StorageAccountBlobContainer"]);
                var blockBlob = container.GetBlockBlobReference(string.Format(CultureInfo.CurrentCulture, "badgeimage{0}", data.Id));

                blockBlob.UploadFromByteArray(data.BadgeImage, 0, data.BadgeImage.Length, null, null, null);

                data.ImagePath = blockBlob.Uri.ToString();
            }
        }
Ejemplo n.º 17
0
 private static Badge LoadData(BadgeEditDTO data)
 {
     var badgeEntity = new Badge
     {
         BadgeId = data.Id,
         BadgeName = data.Name,
         BadgeTagLine = data.Tagline,
         BadgeDescription = data.Description,
         BadgeTypeId = (int)data.Type,
         BadgePath = data.ImagePath,
         BadgeCreated = data.Created,
         BadgeEffectiveStart = data.EffectiveStartDate,
         BadgeEffectiveEnd = data.EffectiveEndDate,
         BadgePriority = data.Priority,
         MultipleAwardPossible = data.MultipleAwardsPossible,
         DisplayOnce = data.DisplayOnce,
         ManagementApprovalRequired = data.ManagementApprovalRequired,
         ActivityPointsAmount = data.ActivityPointsAmount,
         BadgeAwardValueAmount = data.AwardValueAmount,
         BadgeApprovedById = data.ApprovedById == 0 ? null : (int?)data.ApprovedById,
         BadgeStatusId = (int)data.BadgeStatus,
         BadgeApprovedDate = data.ApprovedDate,
         CreateEmployeeId = data.CreateEmployeeId
     };
     return badgeEntity;
 }
Ejemplo n.º 18
0
        public void AllowedNullEffectiveDates()
        {
            var approvalDate = DateTime.Parse("1/1/2014", CultureInfo.CurrentCulture);
            var dto = new BadgeEditDTO();

            var result = AwardBadges.BadgeValidForDate(approvalDate, dto);

            Assert.IsTrue(result);
        }
Ejemplo n.º 19
0
 public static bool AllowedToBeAwarded(BadgeEditDTO potentialBadge, IList<BadgeAwardDTO> earnedBadges)
 {
     var returnValue = potentialBadge.MultipleAwardsPossible
            || !earnedBadges.Any(eb => eb.BadgeId == potentialBadge.Id);
     return returnValue;
 }