Ejemplo n.º 1
0
        protected override void ExecuteRequest(HttpContext context)
        {
            (bool isOk, User user) = CheckClaimsForUser(Request, context, _userRepository);
            if (!isOk || user == null)
            {
                return;
            }

            Avatar avatar = _avatarRepository.GetByUser(user).GetAwaiter().GetResult();

            if (avatar != null)
            {
                IEnumerable <Skin> skins = _skinRepository.GetAll().GetAwaiter().GetResult();
                IEnumerable <GetAvailableSkinsDTOResponse> skinsDTOReponse = skins.Select(skin =>
                {
                    SkinInformations skinInformations = SkinHandlers.Handle(user, skin, _avatarRepository, _categoryRepository, _questTypeRepository, _questRepository).GetAwaiter().GetResult();
                    return(new GetAvailableSkinsDTOResponse(skin.Id, skin.Name, skin.LevelMin, skinInformations.Description, skinInformations.Unlocked));
                }).Where(skin =>
                         skin.Unlocked
                         );

                if (skinsDTOReponse != null)
                {
                    string skinsJson = JsonSerializer.Serialize(skinsDTOReponse);
                    context.Response.StatusCode = StatusCodes.Status200OK;
                    context.Response.WriteAsync(skinsJson).GetAwaiter().GetResult();
                    return;
                }
            }
            context.Response.StatusCode = StatusCodes.Status400BadRequest;
        }
Ejemplo n.º 2
0
        protected override void ExecuteRequest(HttpContext context)
        {
            (bool isOk, User user) = CheckClaimsForUser(Request, context, _userRepository);
            if (!isOk || user == null)
            {
                return;
            }

            Skin skin = _skinRepository.Get(Request.Id).GetAwaiter().GetResult().FirstOrDefault();

            if (skin != null)
            {
                Avatar avatar = _avatarRepository.GetByUser(user).GetAwaiter().GetResult();

                if (avatar != null && avatar.Level >= skin.LevelMin)
                {
                    avatar.SkinId = Request.Id;
                    avatar        = _avatarRepository.Update(avatar).GetAwaiter().GetResult();
                    if (avatar != null)
                    {
                        string avatarJson = JsonSerializer.Serialize(avatar);
                        context.Response.StatusCode = StatusCodes.Status200OK;
                        context.Response.WriteAsync(avatarJson).GetAwaiter().GetResult();
                        return;
                    }
                }
            }
            context.Response.StatusCode = StatusCodes.Status400BadRequest;
        }
Ejemplo n.º 3
0
        protected override void ExecuteRequest(HttpContext context)
        {
            (bool isOk, User user) = CheckClaimsForUser(Request, context, _userRepository);
            if (!isOk || user == null)
            {
                return;
            }

            Avatar avatar = _avatarRepository.GetByUser(user).GetAwaiter().GetResult();

            UserInfo userInfo = new UserInfo(user, avatar);

            string userInfoJson = JsonSerializer.Serialize(userInfo);

            context.Response.StatusCode = StatusCodes.Status200OK;
            context.Response.WriteAsync(userInfoJson).GetAwaiter().GetResult();
        }
Ejemplo n.º 4
0
        protected override void ExecuteRequest(HttpContext context)
        {
            (bool isOk, User user) = CheckClaimsForUser(Request, context, _userRepository);
            if (!isOk || user == null)
                return;

            Avatar avatar = _avatarRepository.GetByUser(user).GetAwaiter().GetResult();

            if (avatar != null)
            {
                avatar.Size = Request.NewSize;
                avatar = _avatarRepository.Update(avatar).GetAwaiter().GetResult();
                if (avatar != null)
                {
                    string avatarJson = JsonSerializer.Serialize(avatar);
                    context.Response.StatusCode = StatusCodes.Status200OK;
                    context.Response.WriteAsync(avatarJson).GetAwaiter().GetResult();
                }
            }
            else
                context.Response.StatusCode = StatusCodes.Status400BadRequest;
        }
Ejemplo n.º 5
0
        public static async Task <SkinInformations> Handle(User user, Skin skin, IAvatarRepository avatarRepository, ICategoryRepository categoryRepository, IQuestTypeRepository questTypeRepository, IQuestRepository questRepository)
        {
            Skin.SkinNameAsEnum skinName         = skin.Name.AsSkinEnum();
            SkinInformations    skinInformations = null;
            IEnumerable <Quest> quests           = null;

            switch (skinName)
            {
            case Skin.SkinNameAsEnum.man_default:
            case Skin.SkinNameAsEnum.woman_default:
                skinInformations = new SkinInformations("default skin", true);
                break;

            case Skin.SkinNameAsEnum.man_pyjama:
            case Skin.SkinNameAsEnum.woman_pyjama:
                Dbo.Category sleepCategory = await categoryRepository.GetByName(Dbo.Category.CategoryAsEnum.Sleep.ToString());

                quests = (await questRepository.Get(user, sleepCategory.Id, questTypeRepository, null))
                         .Where(quest => {
                    QuestState questState = QuestHandlers.QuestHandlers.Create(quest, user, questTypeRepository).GetState();

                    return(questState == QuestState.Claimed || questState == QuestState.Finished);
                });
                int numberOfSleepQuestCompleted = quests.Count();
                int numberOfSleepQuestGoal      = 5;
                skinInformations = new SkinInformations($"do at least {numberOfSleepQuestGoal} sleep quests (current: {numberOfSleepQuestCompleted})", numberOfSleepQuestCompleted >= numberOfSleepQuestGoal);
                break;

            case Skin.SkinNameAsEnum.man_sportive:
            case Skin.SkinNameAsEnum.woman_sportive:
                Dbo.Category PACategory = await categoryRepository.GetByName(Dbo.Category.CategoryAsEnum.PhysicalActivity.ToString());

                quests = (await questRepository.Get(user, PACategory.Id, questTypeRepository, null))
                         .Where(quest => {
                    QuestState questState = QuestHandlers.QuestHandlers.Create(quest, user, questTypeRepository).GetState();

                    return(questState == QuestState.Claimed || questState == QuestState.Finished);
                });
                int numberOfPAQuestCompleted = quests.Count();
                int numberOfPAQuestGoal      = 5;
                skinInformations = new SkinInformations($"do at least {numberOfPAQuestGoal} sleep quests (current: {numberOfPAQuestCompleted})", numberOfPAQuestCompleted >= numberOfPAQuestGoal);
                break;

            case Skin.SkinNameAsEnum.man_fancy:
            case Skin.SkinNameAsEnum.woman_fancy:
            case Skin.SkinNameAsEnum.man_funny:
            case Skin.SkinNameAsEnum.woman_funny:
            case Skin.SkinNameAsEnum.man_cook:
            case Skin.SkinNameAsEnum.woman_cook:
                Avatar avatar = await avatarRepository.GetByUser(user);

                skinInformations = new SkinInformations($"reach level {skin.LevelMin} (current: {avatar.Level})", avatar.Level >= skin.LevelMin);
                break;

            default:
            case Skin.SkinNameAsEnum.unknown:
                skinInformations = new SkinInformations("???", false);
                break;
            }
            return(skinInformations);
        }