Align .editorconfig files
When debugging only app.Services.GetRequiredService<IPCRBService>(); Injected AppSettings instead of using GetEnvironmentVariable at Services level Get ready to use VSCode IDE
This commit is contained in:
@ -4,6 +4,7 @@ using System.Net.Mail;
|
||||
using System.Text;
|
||||
|
||||
using MesaFabApproval.API.Utilities;
|
||||
using MesaFabApproval.Models;
|
||||
using MesaFabApproval.Shared.Models;
|
||||
using MesaFabApproval.Shared.Utilities;
|
||||
|
||||
@ -51,17 +52,16 @@ public class MRBService : IMRBService {
|
||||
IMemoryCache cache,
|
||||
IUserService userService,
|
||||
IApprovalService approvalService,
|
||||
ISmtpService smtpService) {
|
||||
ISmtpService smtpService,
|
||||
AppSettings appSettings) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_dalService = dalService ?? throw new ArgumentNullException("IDalService not injected");
|
||||
_cache = cache ?? throw new ArgumentNullException("IMemoryCache not injected");
|
||||
_userService = userService ?? throw new ArgumentNullException("IUserService not injected");
|
||||
_approvalService = approvalService ?? throw new ArgumentNullException("IApprovalService not injected");
|
||||
_smtpService = smtpService ?? throw new ArgumentNullException("ISmtpService not injected");
|
||||
_siteBaseUrl = Environment.GetEnvironmentVariable("NewFabApprovalBaseUrl") ??
|
||||
throw new ArgumentNullException("FabApprovalBaseUrl environment variable not found");
|
||||
_mrbAttachmentPath = Environment.GetEnvironmentVariable("FabApprovalMrbAttachmentPath") ??
|
||||
throw new ArgumentNullException("FabApprovalMrbAttachmentPath environment variable not found");
|
||||
_siteBaseUrl = appSettings.SiteBaseUrl;
|
||||
_mrbAttachmentPath = appSettings.MrbAttachmentPath;
|
||||
}
|
||||
public async Task CreateNewMRB(MRB mrb) {
|
||||
try {
|
||||
@ -100,7 +100,7 @@ public class MRBService : IMRBService {
|
||||
if (rowsCreated <= 0) throw new Exception("Unable to create new MRB");
|
||||
|
||||
mrb = await GetMRBByTitle(mrb.Title, true);
|
||||
|
||||
|
||||
_cache.Set($"mrb{mrb.MRBNumber}", mrb, DateTimeOffset.Now.AddHours(1));
|
||||
_cache.Set($"mrb{mrb.Title}", mrb, DateTimeOffset.Now.AddHours(1));
|
||||
|
||||
@ -160,7 +160,7 @@ public class MRBService : IMRBService {
|
||||
_cache.Set("mrbNumbers", mrbNumbers);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to determine if {number} is a valid MRB#, because {ex.Message}");
|
||||
@ -205,7 +205,7 @@ public class MRBService : IMRBService {
|
||||
if (string.IsNullOrWhiteSpace(title)) throw new ArgumentException("Title cannot be null or empty");
|
||||
|
||||
MRB? mrb = null;
|
||||
|
||||
|
||||
if (!bypassCache) mrb = _cache.Get<MRB>($"mrb{title}");
|
||||
|
||||
if (mrb is null) {
|
||||
@ -275,7 +275,7 @@ public class MRBService : IMRBService {
|
||||
IEnumerable<MRB>? allMrbs = _cache.Get<IEnumerable<MRB>>("allMrbs");
|
||||
if (allMrbs is not null) {
|
||||
List<MRB> mrbList = allMrbs.ToList();
|
||||
mrbList.RemoveAll(m => m.MRBNumber ==mrb.MRBNumber);
|
||||
mrbList.RemoveAll(m => m.MRBNumber == mrb.MRBNumber);
|
||||
mrbList.Add(mrb);
|
||||
_cache.Set("allMrbs", mrbList, DateTimeOffset.Now.AddHours(1));
|
||||
}
|
||||
@ -302,7 +302,6 @@ public class MRBService : IMRBService {
|
||||
|
||||
if (rowsAffected <= 0) throw new Exception("Unable to create MRB action in database");
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"An exception occurred when attempting to create new MRB action. Exception: {ex.Message}");
|
||||
throw;
|
||||
@ -316,7 +315,7 @@ public class MRBService : IMRBService {
|
||||
if (mrbNumber <= 0) throw new ArgumentException($"{mrbNumber} is not a valid MRB number");
|
||||
|
||||
IEnumerable<MRBAction>? mrbActions = null;
|
||||
|
||||
|
||||
if (!bypassCache)
|
||||
_cache.Get<IEnumerable<MRBAction>>($"mrbActions{mrbNumber}");
|
||||
|
||||
@ -542,7 +541,7 @@ public class MRBService : IMRBService {
|
||||
foreach (MRBAction action in await GetMRBActionsForMRB(mrbNumber, false)) {
|
||||
string sql = $"select * from MRBActionAttachment where ActionID = {action.ActionID};";
|
||||
|
||||
IEnumerable<MRBActionAttachment> newAttachments =
|
||||
IEnumerable<MRBActionAttachment> newAttachments =
|
||||
(await _dalService.QueryAsync<MRBActionAttachment>(sql)).ToList();
|
||||
|
||||
attachments.AddRange(newAttachments);
|
||||
@ -574,7 +573,7 @@ public class MRBService : IMRBService {
|
||||
|
||||
int rowsDeleted = await _dalService.ExecuteAsync(sql);
|
||||
|
||||
if (rowsDeleted <= 0)
|
||||
if (rowsDeleted <= 0)
|
||||
throw new Exception($"No attachments found in the database with attachment ID {attachment.AttachmentID}");
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"An exception occurred when attempting to delete an attachment. Exception: {ex.Message}");
|
||||
@ -781,7 +780,7 @@ public class MRBService : IMRBService {
|
||||
|
||||
sw.Write(sw.NewLine);
|
||||
|
||||
foreach (DataRow dr in dt.Rows) {
|
||||
foreach (DataRow dr in dt.Rows) {
|
||||
for (int i = 0; i < dt.Columns.Count; i++) {
|
||||
if (!Convert.IsDBNull(dr[i])) {
|
||||
string? value = dr[i].ToString();
|
||||
@ -838,7 +837,7 @@ public class MRBService : IMRBService {
|
||||
string convertFromPart = string.Empty;
|
||||
string convertToCustomer = string.Empty;
|
||||
string convertToPart = string.Empty;
|
||||
|
||||
|
||||
string[] convertFrom = action.ConvertFrom.Split(" ");
|
||||
if (convertFrom.Length > 1) {
|
||||
convertFromCustomer = convertFrom[0];
|
||||
@ -936,4 +935,4 @@ public class MRBService : IMRBService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user