public async Task <ActionResult <FullUser> > CreateCornaddy([FromBody] CreateCornaddyRequest request) { try { if (string.IsNullOrWhiteSpace(request.Id)) { throw new ArgumentNullException("id"); } var platformId = BitcornUtils.GetPlatformId(request.Id); var user = await BitcornUtils.GetUserForPlatform(platformId, _dbContext).FirstOrDefaultAsync(); if (user != null) { var walletResponse = await WalletUtils.CreateCornaddy(_dbContext, user.UserWallet, _configuration); if (!walletResponse.WalletAvailable) { return(StatusCode((int)HttpStatusCode.ServiceUnavailable)); } return(BitcornUtils.GetFullUser(user, user.UserIdentity, user.UserWallet, user.UserStat)); } else { return(StatusCode(500)); } } catch (Exception e) { await BITCORNLogger.LogError(_dbContext, e); throw e; } }
public async Task <ActionResult <FullUser> > CreateCornaddy([FromBody] CreateCornaddyRequest request) { try { if (this.GetCachedUser() != null) { throw new InvalidOperationException(); } if (string.IsNullOrWhiteSpace(request.Id)) { throw new ArgumentNullException("id"); } var platformId = BitcornUtils.GetPlatformId(request.Id); var user = await BitcornUtils.GetUserForPlatform(platformId, _dbContext).FirstOrDefaultAsync(); if (user != null) { var walletResponse = await WalletUtils.CreateCornaddy(_dbContext, user.UserWallet, _configuration); if (!walletResponse.WalletAvailable) { user.UserWallet.CornAddy = "<no enabled wallets found>"; await _dbContext.SaveAsync(); return(StatusCode(200)); //return StatusCode((int)HttpStatusCode.ServiceUnavailable); } return(BitcornUtils.GetFullUser(user, user.UserIdentity, user.UserWallet, user.UserStat)); } else { return(StatusCode(500)); } } catch (Exception e) { await BITCORNLogger.LogError(_dbContext, e, JsonConvert.SerializeObject(request)); throw e; } }