From b60bceea779b5ec4d5f58c256786e5c86c59cfb9 Mon Sep 17 00:00:00 2001 From: Sydney Date: Fri, 22 Mar 2024 02:08:27 -0400 Subject: [PATCH] clean up frontend. --- Pages/SharedEmailPage.cs | 9 ++++++--- Pages/Subscribe.cshtml.cs | 13 +++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Pages/SharedEmailPage.cs b/Pages/SharedEmailPage.cs index f5bfc51..97df5ed 100644 --- a/Pages/SharedEmailPage.cs +++ b/Pages/SharedEmailPage.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using Newtonsoft.Json; using System.Net.Http.Headers; +using System.Net.Http.Json; using System.Text; namespace weather_consumer.Pages; @@ -14,7 +15,6 @@ public abstract class SharedEmailPage : PageModel public SharedEmailPage(ILogger logger) { - httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _logger = logger; } @@ -32,11 +32,14 @@ public Task RemoveEmail(Email email) private async Task WriteEmail(Email email, bool isSubbing) { string json = JsonConvert.SerializeObject(email); - var data = new StringContent(json, Encoding.UTF8, "application/json"); + StringContent data = new StringContent(json, Encoding.UTF8, "application/json"); string URL = isSubbing ? Program.WEATHER_BACKEND_PROVIDER + "emails/add/" : Program.WEATHER_BACKEND_PROVIDER + "emails/remove/"; - using (HttpResponseMessage response = await httpClient.PutAsync(URL, data)) + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, URL); + request.Content = data; + + using (HttpResponseMessage response = await httpClient.SendAsync(request)) { var statusCode = response.StatusCode; if ((int)statusCode != 200) diff --git a/Pages/Subscribe.cshtml.cs b/Pages/Subscribe.cshtml.cs index 175e83a..31c4d44 100644 --- a/Pages/Subscribe.cshtml.cs +++ b/Pages/Subscribe.cshtml.cs @@ -15,19 +15,20 @@ public SubscribeModel(ILogger logger) : base(logger) { } - public async void OnPost(string email, int zipcode) + public void OnPost(string email, int zipcode) { success = false; - if (email is null) { - _logger.LogInformation("Email is null."); + if (email is null) + { return; } - if(zipcode <= 0) { - _logger.LogInformation("Zipcode is 0 or negative."); + if (zipcode <= 0) + { return; } this.email = email; this.zipcode = zipcode; - success = await SaveEmail(new Email(email, zipcode)); + success = SaveEmail(new Email(email, zipcode)).Result; } + }