public async Task <ActionResult <Character> > Post(PostCharacterRequest characterRequest) { HttpContext.VerifyUserHasAnyAcceptedScope("api.writeCharacterData"); var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (string.IsNullOrWhiteSpace(userId)) { return(BadRequest("No userId found.")); } if (!string.IsNullOrWhiteSpace(characterRequest.Id) && !Guid.TryParse(characterRequest.Id, out _)) { return(BadRequest("Invalid character Id.")); } var blobContainerClient = new BlobContainerClient(_configuration["StorageAccountConnectionString"], "characters"); var currentCharactersForUser = await _characterManager.GetRawCharacterBlobsAsync(blobContainerClient, userId); if (currentCharactersForUser.Count >= 20) { return(BadRequest("User already has 20 characters saved.")); } var newCharacter = await _characterManager.SaveCharacterAsync(characterRequest, userId); return(Ok(newCharacter)); }
public async Task <ActionResult <Character> > Post(PostCharacterRequest characterRequest) { HttpContext.VerifyUserHasAnyAcceptedScope("api.writeCharacterData"); var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (string.IsNullOrWhiteSpace(userId)) { return(BadRequest("No userId found.")); } if (!string.IsNullOrWhiteSpace(characterRequest.Id) && !Guid.TryParse(characterRequest.Id, out _)) { return(BadRequest("Invalid character Id.")); } var blobContainerClient = new BlobContainerClient(_configuration["StorageAccountConnectionString"], "characters"); var permission = CharacterPermissionLevel.Owner; if (!string.IsNullOrWhiteSpace(characterRequest.Id)) { permission = await _characterManager.CheckCharacterPermissionLevelForUser(characterRequest.Id, userId); if (permission != CharacterPermissionLevel.Owner && permission != CharacterPermissionLevel.Write) { return(BadRequest("User does not have permission to change this character.")); } } var currentCharactersForUser = await _characterManager.GetRawCharacterBlobsAsync(blobContainerClient, userId); if (currentCharactersForUser.Count >= _characterLimitPerUser) { return(BadRequest($"User already has {_characterLimitPerUser} characters saved.")); } var newCharacter = await _characterManager.SaveCharacterAsync(characterRequest, userId, permission); return(Ok(newCharacter)); }