public override async Task <IActionResult> Post([FromBody] Player docIn) { string username = docIn.Username; // make sure username is included if (username == null) { return(MissingPropertyResult("username")); } // make sure username is valid if (IsInvalidUsername(username)) { return(BadRequest(INVALID_USERNAME)); } // make sure username does not already exist try { Player doc = await CosmosRepo.QueryDocument <Player>(CollectionName, $"SELECT * FROM Users u WHERE u.username='******'"); return(BadRequest(USERNAME_EXISTS)); } catch (DocumentClientException) { } // set list fields to empty lists docIn.Bands = new List <string>(); docIn.Events = new List <string>(); return(await base.Post(docIn)); }
public async Task <IActionResult> GetUserByName(string username) { // username must be all alphanumeric characters or underscores if (IsInvalidUsername(username)) { return(BadRequest(INVALID_USERNAME)); } // SQL query Player doc; try { doc = await CosmosRepo.QueryDocument <Player>(CollectionName, $"SELECT * FROM Players u WHERE u.username='******'"); } catch (DocumentClientException) { return(NotFound(USERNAME_NOT_FOUND)); } return(Ok(doc)); }