コード例 #1
0
        public UserVerifyResult Verify(Guid token)
        {
            var account = _accountQueryService.GetByToken(token);

            if (account == null)
            {
                return(UserVerifyResult.TokenChanged);
            }

            var now = DateTime.UtcNow;

            if (account.TokenExpireDate > now)
            {
                return(UserVerifyResult.TokenExpired);
            }

            if (account.VerifiedOn.HasValue)
            {
                return(UserVerifyResult.AlreadyVerified);
            }

            using (var contextScope = ContextScopeFactory.Create())
            {
                account.VerifiedOn      = DateTime.Now;
                account.Token           = null;
                account.TokenExpireDate = null;
                account.Status          = Models.Enums.AccountStatus.Active;

                _accountRepository.Update(Mapper.Map <Account>(account));

                contextScope.SaveChanges();
            }

            return(UserVerifyResult.Ok);
        }
コード例 #2
0
        private void EditAchivmentProperties(IEnumerable <Faw.Models.Domain.ExpressionProperty> expressionProperties, Guid achivmentId)
        {
            using (var contextScope = ContextScopeFactory.Create())
            {
                foreach (var expressionProperty in expressionProperties.ToList())
                {
                    var expr = _expressionPropertyRepository.Get(expressionProperty.EntityId);

                    if (expr == null)
                    {
                        expressionProperty.LeftPropertyValueId  = expressionProperty.LeftPropertyValue.EntityId;
                        expressionProperty.RightPropertyValueId = expressionProperty.RightPropertyValue.EntityId;
                    }
                    else
                    {
                        expressionProperty.LeftPropertyValue.EntityId  = expressionProperty.LeftPropertyValueId;
                        expressionProperty.RightPropertyValue.EntityId = expressionProperty.RightPropertyValueId;
                    }

                    _expressionPropertyRepository.Save(expressionProperty);
                    UpdatePropertyValue(expressionProperty.LeftPropertyValue);
                    UpdatePropertyValue(expressionProperty.RightPropertyValue);
                }

                contextScope.SaveChanges();
            }
        }
コード例 #3
0
        private void SaveInternal(Achivment achivment)
        {
            var now = DateTime.UtcNow;

            using (var contextScope = ContextScopeFactory.Create())
            {
                var domainAchivment = _mapper.Map <Faw.Models.Domain.Achivment>(achivment);

                domainAchivment.UpdatedOn = domainAchivment.CreatedOn = now;

                _achivmentRepository.Save(domainAchivment);

                var expIds = domainAchivment.ExpressionProperties.Select(x => x.EntityId);

                var toRemove =
                    _expressionPropertyRepository.GetWhere(
                        x => !expIds.Contains(x.EntityId) && x.AchivmentId == domainAchivment.EntityId)
                    .Select(x => x.EntityId);

                _expressionPropertyRepository.DeleteRange(toRemove);

                EditAchivmentProperties(domainAchivment.ExpressionProperties, domainAchivment.EntityId);

                contextScope.SaveChanges();
            }
        }
コード例 #4
0
        public void Edit(User user)
        {
            using (var contextScope = ContextScopeFactory.Create())
            {
                //var domainUser = _userRepository.GetById(user.UserId);

                //Mapper.Map(user, domainUser);

                _userRepository.Save(_mapper.Map <Faw.Models.Domain.User>(user));

                contextScope.SaveChanges();
            }
        }
コード例 #5
0
        public void Create(Family family)
        {
            var domainFamily = Mapper.Map<Faw.Models.Domain.Family>(family);

            using (var contextScope = ContextScopeFactory.Create())
            {
                domainFamily.CreatedOn = domainFamily.UpdatedOn = DateTime.UtcNow;
                
                _familyRepository.Save(domainFamily);

                contextScope.SaveChanges();
            }
        }
コード例 #6
0
        public void AddNewFamilyMember(Guid familyId, Guid userId)
        {
            //TODO: Add check if family exists. and user havent been assigned to any family.
            using (var contextScope = ContextScopeFactory.Create())
            {
                var domainUser = _userRepository.GetById(userId);

                domainUser.FamilyId = familyId;

                _userRepository.Update(domainUser);

                contextScope.SaveChanges();
            }
        }
コード例 #7
0
        public void Create(Quest quest)
        {
            var domainQuest = Mapper.Map <Faw.Models.Domain.Quest>(quest);

            using (var contextScope = ContextScopeFactory.Create())
            {
                domainQuest.CreatedOn  = domainQuest.UpdatedOn = DateTime.UtcNow;
                domainQuest.Expirience = _expirienceQueryService.CalculateExpirience(domainQuest.RequiredLevel,
                                                                                     quest.QuestСomplexity);

                _questRepository.Insert(domainQuest);

                contextScope.SaveChanges();
            }
        }
コード例 #8
0
        private void UpdatePropertyValue(Faw.Models.Domain.PropertyValue propertyValue)
        {
            using (var contextScope = ContextScopeFactory.Create())
            {
                var domainPropertyValue = _propertyValueRepository.GetById(propertyValue.EntityId);

                if (domainPropertyValue != null)
                {
                    _mapper.Map(propertyValue, domainPropertyValue);
                }

                _propertyValueRepository.Save(propertyValue);

                contextScope.SaveChanges();
            }
        }
コード例 #9
0
        public void Edit(Quest quest)
        {
            var domainQuest = GetQuestInternal(quest.QuestId);

            Mapper.Map(quest, domainQuest);

            using (var contextScope = ContextScopeFactory.Create())
            {
                domainQuest.UpdatedOn  = DateTime.UtcNow;
                domainQuest.Expirience = _expirienceQueryService.CalculateExpirience(domainQuest.RequiredLevel,
                                                                                     quest.QuestСomplexity);

                _questRepository.Update(domainQuest);

                contextScope.SaveChanges();
            }
        }
コード例 #10
0
        public Guid Register(User user)
        {
            var domainUser = Mapper.Map <Faw.Models.Domain.User>(user);
            var sh         = new SaltedHash(user.Account.Password);
            var now        = DateTime.UtcNow;

            domainUser.Account.PasswordHash = sh.Hash;
            domainUser.Account.PasswordSalt = sh.Salt;

            domainUser.Account.CreatedOn = now;
            domainUser.Account.UpdatedOn = now;

            domainUser.Account.Token           = Guid.NewGuid();
            domainUser.Account.TokenExpireDate = now.AddHours(1);

            domainUser.Account.Status = AccountStatus.PendingActivation;

            var userType = _userTypeQueryService.GetByName(user.Account.UserType);

            if (userType == null)
            {
                throw new ArgumentNullException(nameof(userType));
            }

            domainUser.UserTypeId = userType.UserTypeId;
            domainUser.AccountId  = domainUser.Account.EntityId;

            domainUser.PlayerInfo = new PlayerInfo
            {
                ExpirienceAmount = 0,
                Level            = 1
            };

            domainUser.PlayerInfoId = domainUser.PlayerInfo.EntityId;

            using (var contextScope = ContextScopeFactory.Create())
            {
                _userRepository.Save(domainUser);
                _accountRepository.Save(domainUser.Account);
                _playerInfoRepository.Save(domainUser.PlayerInfo);

                contextScope.SaveChanges();
            }

            return(domainUser.Account.Token.Value);
        }
コード例 #11
0
        public void Edit(Family family)
        {
            var existFamily = GetFamilyInternal(family.FamilyId);

            if (existFamily == null)
                throw new ArgumentNullException(nameof(existFamily));

            Mapper.Map(family, existFamily);

            using (var contextScope = ContextScopeFactory.Create())
            {
                existFamily.UpdatedOn = DateTime.UtcNow;

                _familyRepository.Update(existFamily);

                contextScope.SaveChanges();
            }
        }
コード例 #12
0
        public void AdjustPlayerExpirience(Guid userId, decimal expirienceAmount)
        {
            var user = _userQueryService.Get(userId);

            using (var contextScope = ContextScopeFactory.Create())
            {
                var domain = _playerInfoRepository.GetById(user.PlayerInfoId);

                var result = _expirienceQueryService.ApplayExpirience(user.PlayerInfo, expirienceAmount);

                domain.ExpirienceAmount = result.ResultExpitience;
                domain.Level            = result.ResultLevel;

                _playerInfoRepository.Update(domain);

                contextScope.SaveChanges();
            }
        }
コード例 #13
0
        public void UpdateQuestStatus(Guid userQuestId, UserQuestStatus status)
        {
            Faw.Models.Domain.UserQuest userQuest;

            using (var contextScope = ContextScopeFactory.Create())
            {
                userQuest = _userQuestRepository.GetUserQuest(userQuestId);

                userQuest.UserQuestStatus = _mapper.Map <Faw.Models.Domain.Enums.UserQuestStatus>(status);
                _userQuestRepository.Save(userQuest);

                contextScope.SaveChanges();
            }

            switch (status)
            {
            case UserQuestStatus.Verified:
                _playerInfoService.AdjustPlayerExpirience(userQuest.UserId, userQuest.Quest.Expirience);
                break;
            }
        }
コード例 #14
0
        public void AssignQuestUser(Guid userId, Guid questId)
        {
            var quest = _questQueryService.GetById(questId);

            var userQuest = new UserQuest
            {
                UserId          = userId,
                QuestId         = questId,
                UserQuestStatus = UserQuestStatus.Assigned,
                QuestСomplexity = quest.QuestСomplexity
            };

            userQuest.CreatedOn = userQuest.UpdatedOn = DateTime.UtcNow;

            using (var contextScope = ContextScopeFactory.Create())
            {
                _userQuestRepository.Insert(_mapper.Map <Faw.Models.Domain.UserQuest>(userQuest));

                contextScope.SaveChanges();
            }
        }