Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ychung-mot committed Apr 16, 2024
1 parent 0e4fb29 commit b48a9f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/StrDss.Service/EmailMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task<string> SendEmailAsync(EmailContent emailContent)
var token = await _chesTokenApi.GetTokenAsync();
var chesUrl = _config.GetValue<string>("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");
Expand Down
2 changes: 1 addition & 1 deletion server/StrDss.Service/EmailTemplates/EmailTemplateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmailAttachment> Attachments { get; set; }
public IEnumerable<EmailAttachment> Attachments { get; set; } = Enumerable.Empty<EmailAttachment>();

public string GetPreviewContent()
{
Expand Down
16 changes: 8 additions & 8 deletions server/StrDss.Service/FieldValidatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ private List<string> ValidateStringField<T>(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;
Expand All @@ -120,7 +120,7 @@ private List<string> ValidateStringField<T>(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}.");
}
}
Expand Down Expand Up @@ -159,14 +159,14 @@ private List<string> ValidateDateField<T>(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;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ private List<string> ValidateNumberField<T>(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) ?? "";
Expand Down

0 comments on commit b48a9f9

Please sign in to comment.