public async Task CreateUserPageSizeChoice([FromBody] UserPageSizeChoice userPageSizeChoice) { try { string userPrincipalName = this.HttpContext.User.FindFirst(ClaimTypes.Upn)?.Value.ToLower(); if (string.IsNullOrEmpty(userPrincipalName)) { this.telemetryClient.TrackTrace($"There's no user principal name claim. Parameters:{userPageSizeChoice}", SeverityLevel.Error); this.HttpContext.Response.ContentType = "text/plain"; this.HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized; await this.HttpContext.Response.WriteAsync("There's no user principal name claim"); } await this.userPageSizeChoiceDataRepository.CreateOrUpdateUserPageSizeChoiceDataAsync(userPrincipalName, userPageSizeChoice.PageSize, userPageSizeChoice.PageId); this.telemetryClient.TrackEvent($"Created/Updated user Page size : {JsonConvert.SerializeObject(userPageSizeChoice)}"); this.HttpContext.Response.ContentType = "text/plain"; this.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; await this.HttpContext.Response.WriteAsync("Choice successfully saved."); } catch (MsalException ex) { this.telemetryClient.TrackTrace($"An error occurred in createUserPageSizeChoice: {ex.Message}. Parameters: {this.HttpContext.User.FindFirst(ClaimTypes.Upn)?.Value.ToLower()}:{JsonConvert.SerializeObject(userPageSizeChoice)}", SeverityLevel.Error); this.telemetryClient.TrackException(ex); } catch (Exception ex) { this.telemetryClient.TrackTrace($"An error occurred in createUserPageSizeChoice: {ex.Message}. Parameters:{this.HttpContext.User.FindFirst(ClaimTypes.Upn)?.Value.ToLower()}:{JsonConvert.SerializeObject(userPageSizeChoice)}", SeverityLevel.Error); this.telemetryClient.TrackException(ex); this.HttpContext.Response.ContentType = "text/plain"; this.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; await this.HttpContext.Response.WriteAsync("An error occurred while calling the downstream API\n" + ex.Message); } }
public async Task <IActionResult> CreateUserPageSizeChoiceAsync([FromBody] UserPageSizeChoice userPageSizeChoice) { try { await this.userPageSizeChoiceDataRepository.CreateOrUpdateUserPageSizeChoiceDataAsync(userPageSizeChoice.PageSize, userPageSizeChoice.PageId, this.UserObjectId); return(this.Ok()); } catch (Exception ex) { this.logger.LogError(ex, $"An error occurred in CreateUserPageSizeChoiceAsync: {ex.Message}. UserObjectId:{this.UserObjectId}"); throw; } }