public async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "put", Route = "PutUser/{Id}")] Common.Models.UserProfile userProfile, HttpRequest req, string Id, ILogger log) { log.LogInformation("PUT - Put User requested"); try { if (!RIPAAuthorization.ValidateUserOrAdministratorRole(req, log).ConfigureAwait(false).GetAwaiter().GetResult()) { return(new UnauthorizedResult()); } } catch (Exception ex) { log.LogError(ex.Message); return(new UnauthorizedResult()); } if (!string.IsNullOrEmpty(userProfile.OfficerId) && userProfile.OfficerId.Length != 9) { return(new BadRequestObjectResult("OfficerId must be 9 chars")); } if (string.IsNullOrEmpty(userProfile.OfficerId)) { int officerId = 100000000; string query = "SELECT VALUE c FROM c ORDER BY c.officerId DESC OFFSET 0 LIMIT 1"; IEnumerable <Common.Models.UserProfile> maxOfficer = await _userProfileCosmosDbService.GetUserProfilesAsync(query); Common.Models.UserProfile maxId = maxOfficer.FirstOrDefault(); if (maxId != null) { officerId = int.Parse(maxId.OfficerId); officerId++; } userProfile.OfficerId = officerId.ToString(); } userProfile.Id = Id; await _userProfileCosmosDbService.UpdateUserProfileAsync(Id, userProfile); return(new OkObjectResult(userProfile)); }
public async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("GET - Get Users requested"); try { if (!RIPAAuthorization.ValidateAdministratorRole(req, log).ConfigureAwait(false).GetAwaiter().GetResult()) { return(new UnauthorizedResult()); } } catch (Exception ex) { log.LogError(ex.Message); return(new UnauthorizedResult()); } var response = await _userProfileCosmosDbService.GetUserProfilesAsync("SELECT * FROM c ORDER BY c.name"); return(new OkObjectResult(response)); }