예제 #1
0
        public async Task <IActionResult> BuyChampion([FromBody] ApiChampions champion)
        {
            var user = await _userManager.GetUserAsync(User);

            var result = await _championsService.BuyChampionForUser(champion, user.UserName);

            return(Ok(result));
        }
예제 #2
0
        public async Task <string> BuyChampionForUser(ApiChampions champion, string userName)
        {
            var account = await _accountRepository.getUserByUsername(userName);

            if (account.AccountStatistics.Gold < champion.Cost)
            {
                return("Insufficient gold!");
            }
            Champions champ = await GetChampionFromDB(champion);

            ChampionsOwned champOwned = CreateChampionForAccount(userName, champ);
            await _championsRepository.BuyChampionForAccount(champOwned);

            return("Character successfully added to your collection!");
        }
예제 #3
0
 public static Champions converToDbModel(ApiChampions ApiModel)
 {
     return(new Champions {
         Name = ApiModel.Name, Avatar = ApiModel.Avatar, Cost = ApiModel.Cost, Icon = ApiModel.Icon, Story = ApiModel.Story
     });
 }
예제 #4
0
 private async Task <Champions> GetChampionFromDB(ApiChampions champion)
 {
     return(await _championsRepository.getChampionByName(champion.Name));
 }