Example #1
0
        public async Task <ActionResult> Register(SummonerModel model)
        {
            ViewModel = await CreateViewModelAsync();

            if (!ModelState.IsValid)
            {
                return(Error(ModelState));
            }

            // Rule: Summoner must not be registered to a User.
            if (await Summoners.IsSummonerRegistered(model.Region, model.SummonerName))
            {
                return(Error("Summoner is already registered."));
            }

            // Rule: Summoner must exist.
            var cacheKey = string.Concat(model.Region, ":", model.SummonerName).ToLowerInvariant();
            var summoner = await CacheUtil.GetItemAsync(cacheKey,
                                                        () => Riot.FindSummonerAsync(model.Region, model.SummonerName));

            if (summoner == null)
            {
                return(Error("Summoner not found."));
            }

            return(Success());
        }
Example #2
0
 private Task <Summoner> FindSummonerAsync(string region, string summonerName)
 {
     return(CacheUtil.GetItemAsync($"{region}:{summonerName}".ToLowerInvariant(),
                                   () => Riot.FindSummonerAsync(region, summonerName)));
 }