Ejemplo n.º 1
0
        private void GiveAchievement(AccountGroupPerson accountGroupPerson, Achievement achievement, DateTime awardedOn)
        {
            PersonWallet wallet = accountGroupPerson.Person.Wallets.Single(x => x.AccountGroupId == accountGroupPerson.AccountGroupId);

            wallet.Value += achievement.Value;
            AwardedAchievement award = new AwardedAchievement()
            {
                Achievement   = achievement,
                AchievementId = achievement.Id,
                AwardDate     = awardedOn,
            };

            Context.Add(award);
            Context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void ActivateSeason_InvalidStartDate_ThrowsException()
        {
            var    fakeContext = new Mock <IDatabaseContext>();
            Person person      = new Person()
            {
                Id = 100
            };

            AccountGroupPerson personJoin = new AccountGroupPerson()
            {
                Person          = person,
                PersonId        = person.Id,
                PermissionLevel = PermissionLevel.Admin
            };
            AccountGroup accountGroup = new AccountGroup()
            {
                Id = 1000,
                AccountGroupPeople = new List <AccountGroupPerson>()
                {
                    personJoin,
                }
            };

            personJoin.AccountGroup   = accountGroup;
            personJoin.AccountGroupId = accountGroup.Id;
            person.AccountGroupPeople = new[] { personJoin };
            Season season = new Season
            {
                Id             = 2,
                IsActive       = false,
                AccountGroup   = accountGroup,
                StartDate      = null,
                EndDate        = DateTime.Today,
                AccountGroupId = accountGroup.Id,
            };

            fakeContext.Setup(x => x.List <Season>()).Returns(new[] { season }.AsQueryable());
            fakeContext.Setup(x => x.List <Person>()).Returns(new[] { person }.AsQueryable());
            SeasonManagement management = new SeasonManagement(fakeContext.Object, 100);

            management.ActivateSeason(2);
        }
Ejemplo n.º 3
0
        public void GiveAchievement(AchievementAllocation allocation)
        {
            //obvious check
            if (allocation == null)
            {
                throw new ArgumentNullException(nameof(allocation));
            }
            //do some not so obvious things to self diagnose
            allocation.Validate();

            //validate this key
            var key = Context.List <ApiKey>().Single(x => x.Key == allocation.ApiKey);

            if (!key.IsActive)
            {
                throw new UnauthorizedAccessException("Api Key has been disabled, please contact your administrator");
            }

            //get the achievement that matches the key
            IEnumerable <Achievement> achievements = key.AccountGroup.Achievements
                                                     .Where(x => x.Key == allocation.AchievementKey);
            //this gets the only active achievement that can be applied
            Season      activeSeason        = key.AccountGroup.CurrentActiveSeason;
            Achievement relevantAchievement = activeSeason.Achievements.SingleOrDefault(x => x.Key == allocation.AchievementKey);

            if (relevantAchievement == null)
            {
                throw new BusinessLogicException("There is no relevant achievement with the created date specified");
            }

            AccountGroupPerson targetPersonJoin = key.AccountGroup.AccountGroupPeople.SingleOrDefault(x => x.CustomKey == allocation.CustomPersonKey);

            if (targetPersonJoin == null)
            {
                throw new UnauthorizedAccessException("Person does not exist, have you setup their customKey correctly?");
            }

            GiveAchievement(targetPersonJoin, relevantAchievement, allocation.CreatedDate);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// creates a normal grouped user. override if you want to use it
        /// </summary>
        /// <param name="p"></param>
        /// <param name="group"></param>
        /// <param name="joinId"></param>
        /// <returns></returns>
        internal static AccountGroupPerson AddToGroup(this Person p, AccountGroup group, int joinId)
        {
            if (p.AccountGroupPeople == null)
            {
                p.AccountGroupPeople = new List <AccountGroupPerson>();
            }

            var join = new AccountGroupPerson {
                AccountGroup = group, AccountGroupId = group.Id, Person = p, PersonId = p.Id
            };

            p.AccountGroupPeople.Add(join);
            if (group.AccountGroupPeople == null)
            {
                group.AccountGroupPeople = new List <AccountGroupPerson>();
            }

            group.AccountGroupPeople.Add(join);
            join.Id = joinId;
            join.PermissionLevel = PermissionLevel.Normal;
            return(join);
        }