public async Task <UserWithToken> GetUserByShindenIdSimpleAsync(ulong id) { using (var db = new Database.UserContext(_config)) { var user = db.Users.Where(x => x.Shinden == id).Include(x => x.GameDeck).AsNoTracking().FirstOrDefault(); if (user == null) { await "User not found!".ToResponse(404).ExecuteResultAsync(ControllerContext); return(null); } TokenData tokenData = null; var currUser = ControllerContext.HttpContext.User; if (currUser.HasClaim(x => x.Type == ClaimTypes.Webpage)) { tokenData = UserTokenBuilder.BuildUserToken(_config, user); } return(new UserWithToken() { Expire = tokenData?.Expire, Token = tokenData?.Token, User = user, }); } }
public async Task <UserWithToken> GetUserByShindenIdAsync(ulong id) { using (var db = new Database.UserContext(_config)) { var user = await db.GetCachedFullUserByShindenIdAsync(id); if (user == null) { await "User not found!".ToResponse(404).ExecuteResultAsync(ControllerContext); return(null); } TokenData tokenData = null; var currUser = ControllerContext.HttpContext.User; if (currUser.HasClaim(x => x.Type == ClaimTypes.Webpage)) { tokenData = UserTokenBuilder.BuildUserToken(_config, user); } return(new UserWithToken() { Expire = tokenData?.Expire, Token = tokenData?.Token, User = user, }); } }
public async Task <UserWithToken> GiveShindenUserAPacksAsync(ulong id, [FromBody] List <Models.CardBoosterPack> boosterPacks) { if (boosterPacks?.Count < 1) { await "Model is Invalid".ToResponse(500).ExecuteResultAsync(ControllerContext); return(null); } var packs = new List <BoosterPack>(); foreach (var pack in boosterPacks) { var rPack = pack.ToRealPack(); if (rPack != null) { packs.Add(rPack); } } if (packs.Count < 1) { await "Data is Invalid".ToResponse(500).ExecuteResultAsync(ControllerContext); return(null); } using (var db = new Database.UserContext(_config)) { var user = await db.GetCachedFullUserByShindenIdAsync(id); if (user == null) { await "User not found!".ToResponse(404).ExecuteResultAsync(ControllerContext); return(null); } var discordId = user.Id; var exe = new Executable($"api-packet u{discordId}", new Task(() => { using (var dbs = new Database.UserContext(_config)) { var botUser = dbs.GetUserOrCreateAsync(discordId).Result; foreach (var pack in packs) { botUser.GameDeck.BoosterPacks.Add(pack); } dbs.SaveChanges(); QueryCacheManager.ExpireTag(new string[] { $"user-{botUser.Id}", "users" }); } })); await _executor.TryAdd(exe, TimeSpan.FromSeconds(1)); TokenData tokenData = null; var currUser = ControllerContext.HttpContext.User; if (currUser.HasClaim(x => x.Type == ClaimTypes.Webpage)) { tokenData = UserTokenBuilder.BuildUserToken(_config, user); } return(new UserWithToken() { Expire = tokenData?.Expire, Token = tokenData?.Token, User = user, }); } }