public bool SetProfilePicture(SetPictureCommand cmd)
        {
            bool isValid = false;

            if (cmd.avatarCategory == AvatarCategory.Special)
            {
                isValid = SpecialPictures.Any(x => x.PictureId == cmd.pictureId);
            }
            else
            {
                var winsPerRace = RaceWins?.GetWinsPerRace((Race)cmd.avatarCategory);
                isValid = winsPerRace >= PictureRange.FirstOrDefault(p => p.PictureId == cmd.pictureId)?.NeededWins;
            }

            if (isValid)
            {
                ProfilePicture = new ProfilePicture()
                {
                    Race      = cmd.avatarCategory,
                    PictureId = cmd.pictureId,
                    IsClassic = cmd.isClassic
                };
            }

            return(isValid);
        }
Beispiel #2
0
        public async Task <IActionResult> SetProfilePicture(
            string battleTag,
            [FromBody] SetPictureCommand command)
        {
            var result = await _commandHandler.UpdatePicture(battleTag, command);

            if (!result)
            {
                return(BadRequest());
            }

            return(Ok());
        }
        public async Task <bool> UpdatePicture(string battleTag, SetPictureCommand command)
        {
            var setting = await _personalSettingsRepository.Load(battleTag);

            if (setting == null)
            {
                var playerProfile = await _playerRepository.LoadPlayerProfile(battleTag);

                setting = new PersonalSetting(battleTag, new List <PlayerOverallStats> {
                    playerProfile
                });
            }

            var result = setting.SetProfilePicture(command.Race, command.PictureId);

            if (!result)
            {
                return(false);
            }

            await _personalSettingsRepository.Save(setting);

            return(true);
        }