Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public static bool AllowedToBeAwarded(BadgeEditDTO potentialBadge, IList <BadgeAwardDTO> earnedBadges)
        {
            var returnValue = potentialBadge.MultipleAwardsPossible ||
                              !earnedBadges.Any(eb => eb.BadgeId == potentialBadge.Id);

            return(returnValue);
        }
Exemplo n.º 3
0
 private void LoadData(BadgeEditDTO data)
 {
     using (this.BypassPropertyChecks)
     {
         this.Id                         = data.Id;
         this.Name                       = data.Name;
         this.Tagline                    = data.Tagline;
         this.Description                = data.Description;
         this.Type                       = data.Type;
         this.ImagePath                  = data.ImagePath;
         this.Created                    = data.Created;
         this.EffectiveStartDate         = data.EffectiveStartDate;
         this.EffectiveEndDate           = data.EffectiveEndDate;
         this.Priority                   = data.Priority;
         this.MultipleAwardsPossible     = data.MultipleAwardsPossible;
         this.DisplayOnce                = data.DisplayOnce;
         this.ManagementApprovalRequired = data.ManagementApprovalRequired;
         this.ActivityPointsAmount       = data.ActivityPointsAmount;
         this.AwardValueAmount           = data.AwardValueAmount;
         this.ApprovedById               = data.ApprovedById;
         this.ApprovedDate               = data.ApprovedDate;
         this.BadgeStatus                = data.BadgeStatus;
         this.Image                      = null;
         this.LoadProperty(CreateEmployeeIdProperty, data.CreateEmployeeId);
         this.LoadChildren(data);
     }
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 private BadgeEditDTO UnloadData()
 {
     using (this.BypassPropertyChecks)
     {
         var returnValue = new BadgeEditDTO
         {
             Id                         = this.Id,
             Name                       = this.Name,
             Tagline                    = this.Tagline,
             Description                = this.Description,
             Type                       = this.Type,
             ImagePath                  = this.ImagePath,
             Created                    = this.Created,
             EffectiveStartDate         = this.EffectiveStartDate,
             EffectiveEndDate           = this.EffectiveEndDate,
             Priority                   = this.Priority,
             MultipleAwardsPossible     = this.MultipleAwardsPossible,
             DisplayOnce                = this.DisplayOnce,
             ManagementApprovalRequired = this.ManagementApprovalRequired,
             ActivityPointsAmount       = this.ActivityPointsAmount,
             AwardValueAmount           = this.AwardValueAmount,
             ApprovedById               = this.ApprovedById,
             ApprovedDate               = this.ApprovedDate,
             BadgeStatus                = this.BadgeStatus,
             BadgeImage                 = this.Image,
             CreateEmployeeId           = ((ICreateEmployee)this).CreateEmployeeId
         };
         this.UnLoadChildren(returnValue);
         return(returnValue);
     }
 }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 private BadgeAwardDTO CreateNewBadgeAward(ActivityInfoDTO activity, BadgeEditDTO potentialBadge)
 {
     return(new BadgeAwardDTO
     {
         BadgeId = potentialBadge.Id,
         AwardAmount = activity.AwardValue == 0 || activity.AwardValue < potentialBadge.AwardValueAmount ? potentialBadge.AwardValueAmount : activity.AwardValue,
         EmployeeId = activity.EmployeeId,
         AwardDate = DateTime.UtcNow
     });
 }
Exemplo n.º 9
0
        public Task <BadgeEditDTO> GetBadgeByIdAsync(int badgeEditId)
        {
            var dto = new BadgeEditDTO
            {
                Id        = 1,
                ImagePath = ImagePath
            };

            dto.BadgeActivities = new List <BadgeActivityEditDTO>();
            return(Task.FromResult(dto));
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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();
            }
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
        public void AllowedOnePreviousOneRequired()
        {
            var dto = new BadgeEditDTO
            {
                ActivityPointsAmount = 1
            };
            var previousActivities = new List <SubmittedActivityItemDTO>();

            previousActivities.Add(new SubmittedActivityItemDTO
            {
                ActivityId = 1,
                Status     = ActivitySubmissionStatus.Complete
            });

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

            Assert.IsTrue(result);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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");
         }
     }
 }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
 public BadgeEditDTO Insert(BadgeEditDTO data)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 21
0
 private void UnLoadChildren(BadgeEditDTO returnValue)
 {
     returnValue.BadgeActivities = ((BadgeActivityEditCollection)this.BadgeActivities).UnloadChildren();
 }
Exemplo n.º 22
0
 public BadgeEditDTO Update(BadgeEditDTO data)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 23
0
 private void LoadChildren(BadgeEditDTO data)
 {
     this.LoadProperty(BadgeActivitiesProperty, new BadgeActivityEditCollection());
     ((BadgeActivityEditCollection)this.BadgeActivities).LoadChildren(data.BadgeActivities);
 }