From b48a9f9c3267661a29b5144599a5c37f4c243608 Mon Sep 17 00:00:00 2001 From: ychung-mot Date: Tue, 16 Apr 2024 15:17:41 -0700 Subject: [PATCH] chore: code cleanup --- server/StrDss.Service/EmailMessageService.cs | 2 +- .../EmailTemplates/EmailTemplateBase.cs | 2 +- server/StrDss.Service/FieldValidatorService.cs | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/StrDss.Service/EmailMessageService.cs b/server/StrDss.Service/EmailMessageService.cs index 6deb08cd..d80e30ab 100644 --- a/server/StrDss.Service/EmailMessageService.cs +++ b/server/StrDss.Service/EmailMessageService.cs @@ -53,7 +53,7 @@ public async Task SendEmailAsync(EmailContent emailContent) var token = await _chesTokenApi.GetTokenAsync(); var chesUrl = _config.GetValue("CHES_URL") ?? ""; - _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}"); + _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token!.AccessToken}"); var jsonContent = emailContent.ToString(); var httpContent = new StringContent(jsonContent, Encoding.UTF8, "application/json"); diff --git a/server/StrDss.Service/EmailTemplates/EmailTemplateBase.cs b/server/StrDss.Service/EmailTemplates/EmailTemplateBase.cs index 83d5a9f3..41a7c8ff 100644 --- a/server/StrDss.Service/EmailTemplates/EmailTemplateBase.cs +++ b/server/StrDss.Service/EmailTemplates/EmailTemplateBase.cs @@ -19,7 +19,7 @@ public EmailTemplateBase(IEmailMessageService emailService) public string Info { get; set; } = ""; public bool Preview { get; set; } = false; public string EmailMessageType { get; set; } = ""; - public IEnumerable Attachments { get; set; } + public IEnumerable Attachments { get; set; } = Enumerable.Empty(); public string GetPreviewContent() { diff --git a/server/StrDss.Service/FieldValidatorService.cs b/server/StrDss.Service/FieldValidatorService.cs index 8b2ec58d..3e3f2338 100644 --- a/server/StrDss.Service/FieldValidatorService.cs +++ b/server/StrDss.Service/FieldValidatorService.cs @@ -90,12 +90,12 @@ private List ValidateStringField(FieldValidationRule rule, T val, int return messages; } - if (!rule.Required && (val is null || val.ToString().IsEmpty())) + if (!rule.Required && (val is null || val!.ToString()!.IsEmpty())) return messages; - string value = Convert.ToString(val); + string value = Convert.ToString(val)!; - if (rule.Required && value.IsEmpty()) + if (rule.Required && value!.IsEmpty()) { messages.Add($"{rowNumPrefix}The {field} field is required."); return messages; @@ -120,7 +120,7 @@ private List ValidateStringField(FieldValidationRule rule, T val, int { if (!Regex.IsMatch(value, rule.RegexInfo.Regex)) { - var message = string.Format(rule.RegexInfo.ErrorMessage, val.ToString()); + var message = string.Format(rule.RegexInfo.ErrorMessage, val!.ToString()); messages.Add($"{rowNumPrefix}{message}."); } } @@ -159,14 +159,14 @@ private List ValidateDateField(FieldValidationRule rule, T val, int r return messages; } - if (!rule.Required && (val is null || val.ToString().IsEmpty())) + if (!rule.Required && (val is null || val!.ToString()!.IsEmpty())) return messages; - var (parsed, parsedDate) = DateUtils.ParseDate(val); + var (parsed, parsedDate) = DateUtils.ParseDate(val!); if (!parsed) { - messages.Add($"{rowNumPrefix}Invalid value. [{val.ToString()}] cannot be converted to a date"); + messages.Add($"{rowNumPrefix}Invalid value. [{val!}] cannot be converted to a date"); return messages; } @@ -197,7 +197,7 @@ private List ValidateNumberField(FieldValidationRule rule, T val, int return messages; } - if (!rule.Required && (val is null || val.ToString().IsEmpty())) + if (!rule.Required && (val is null || val!.ToString()!.IsEmpty())) return messages; string value = Convert.ToString(val) ?? "";