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)); }
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!"); }
public static Champions converToDbModel(ApiChampions ApiModel) { return(new Champions { Name = ApiModel.Name, Avatar = ApiModel.Avatar, Cost = ApiModel.Cost, Icon = ApiModel.Icon, Story = ApiModel.Story }); }
private async Task <Champions> GetChampionFromDB(ApiChampions champion) { return(await _championsRepository.getChampionByName(champion.Name)); }