/** * Set user allow non-essential emails. */ private async Task <APIGatewayProxyResponse> SetUserAllowNonEssentialEmails(IDataStores dataStores, IDictionary <string, string> requestHeaders, JObject requestBody) { Debug.Untested(); Debug.AssertValid(dataStores); Debug.AssertValid(requestHeaders); Debug.AssertValidOrNull(requestBody); try { // Log call LoggingHelper.LogMessage($"UserIdentityService::SetUserAllowNonEssentialEmails()"); // Get the NoSQL DB client AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Check inputs SetUserAllowNonEssentialEmailsRequest setUserAllowNonEssentialEmailsRequest = UserIdentityService_SetUserAllowNonEssentialEmails_LogicLayer.CheckValidSetUserAllowNonEssentialEmailsRequest(requestBody); Debug.AssertValid(setUserAllowNonEssentialEmailsRequest); // Check authenticated endpoint security string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders); Debug.AssertID(loggedInUserId); // Perform logic await UserIdentityService_SetUserAllowNonEssentialEmails_LogicLayer.SetUserAllowNonEssentialEmails(dbClient, loggedInUserId, setUserAllowNonEssentialEmailsRequest); // Respond return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_NO_CONTENT }); } catch (Exception exception) { Debug.Tested(); return(APIHelper.ResponseFromException(exception)); } }
/** * Set user allow non-essential emails. */ public static async Task SetUserAllowNonEssentialEmails(AmazonDynamoDBClient dbClient, string loggedInUserId, SetUserAllowNonEssentialEmailsRequest setUserAllowNonEssentialEmailsRequest) { Debug.Untested(); Debug.AssertValid(dbClient); Debug.AssertID(loggedInUserId); Debug.AssertValid(setUserAllowNonEssentialEmailsRequest); // Load the user User user = await IdentityServiceLogicLayer.FindUserByID(dbClient, loggedInUserId); Debug.AssertValid(user); // Make changes (if necessary) if (user.AllowNonEssentialEmails != setUserAllowNonEssentialEmailsRequest.allowNonEssentialEmails) { user.AllowNonEssentialEmails = setUserAllowNonEssentialEmailsRequest.allowNonEssentialEmails; // Save the user await IdentityServiceDataLayer.SaveUser(dbClient, user); } }