Пример #1
0
        public async Task <IActionResult> Register([FromBody] Credentials credentials)
        {
            int            accStatId = accountService.CreateAccountStatistic(new AccountStatistic());
            ChampionsOwned champ1    = new ChampionsOwned {
                AccountUsername = credentials.Username, ChampionsId = 4, Experience = 0, Lvl = 1
            };
            ChampionsOwned champ2 = new ChampionsOwned {
                AccountUsername = credentials.Username, ChampionsId = 5, Experience = 0, Lvl = 1
            };
            ChampionsOwned champ3 = new ChampionsOwned {
                AccountUsername = credentials.Username, ChampionsId = 6, Experience = 0, Lvl = 1
            };

            championsService.AddChampion(champ1);
            championsService.AddChampion(champ2);
            championsService.AddChampion(champ3);
            var user = new ApplicationUser {
                UserName = credentials.Username, Email = credentials.Username, Gender = credentials.Gender, InGameName = credentials.InGameName, AccountStatisticsId = accStatId
            };

            var result = await _userManager.CreateAsync(user, credentials.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }

            await signInManager.SignInAsync(user, isPersistent : false);

            return(Ok(CreateToken(user)));
        }
Пример #2
0
 public int AddChampion(ChampionsOwned champ)
 {
     _context.Add(champ);
     _context.SaveChanges();
     champ.ChampionOwnedStats = CreateChampionOwnedStats(champ.Id);
     _context.Update(champ);
     _context.SaveChanges();
     return(champ.Id);
 }
Пример #3
0
        private static List <ApiStats> CreateChampionStats(ChampionsOwned stats)
        {
            List <ApiStats> equipmentStatsToReturn = new List <ApiStats>();

            foreach (var equipmentStat in stats.ChampionOwnedStats)
            {
                equipmentStatsToReturn.Add(ChampionOwnedStatMapper.convertToApiModel(equipmentStat));
            }
            return(equipmentStatsToReturn);
        }
Пример #4
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!");
        }
Пример #5
0
 public static ApiChampionsOwned convertToApiModel(ChampionsOwned Model)
 {
     return(new ApiChampionsOwned
     {
         ChampionStats = CreateChampionStats(Model),
         Equipped = Model.Equipped,
         Experience = Model.Experience,
         Lvl = Model.Lvl,
         Champions = new ApiChampions
         {
             Name = Model.Champions.Name,
             Avatar = Model.Champions.Avatar,
             Cost = Model.Champions.Cost,
             Icon = Model.Champions.Icon,
             Story = Model.Champions.Story
         }
     });
 }
Пример #6
0
        public async Task <string> BuyChampionForAccount(ChampionsOwned champion)
        {
            var championId = AddChampion(champion);

            return("Champion added to your collection");
        }
Пример #7
0
 public int AddChampion(ChampionsOwned champ)
 {
     return(_championsRepository.AddChampion(champ));
 }