Gremlin/Gremlin_BlazorServer/Services/HostingService.cs

42 lines
1.8 KiB
C#

using Gremlin_BlazorServer.Data.EntityClasses;
namespace Gremlin_BlazorServer.Services;
public static class HostingService {
// private static IWebHostEnvironment hostingEnvironment;
private static readonly HttpContextAccessor accessor = new();
private static IWebHostEnvironment WebEnv() {
return accessor.HttpContext.RequestServices.GetRequiredService<IWebHostEnvironment>();
}
// public HostingService(IWebHostEnvironment newHostingEnvironment) => hostingEnvironment = newHostingEnvironment;
public static string GetPath() {
return Path.Combine(WebEnv().WebRootPath, "quotes");
}
public static string? GetPath(Quote quote, Contact recipient) {
if (recipient.Account.AccountName is null || quote.Description is null) {
Console.WriteLine("Quote.Path not setable! No acount or desciption in the quote...");
return null;
}
string accountName = recipient.Account.AccountName.Replace(" ", "_");
string description = quote.Description.Replace(" ", "_");
return Path.Combine(WebEnv().WebRootPath, "quotes", accountName, $"{DateTime.Today.Year}-{DateTime.Today.Month}-{recipient.LastName}-{description}");
}
public static string? GetPdfUrl(Quote quote, Contact recipient) {
if (quote.QuotationNumber is null || recipient.Account.AccountName is null || quote.Description is null) {
Console.WriteLine("No path, account, description or quotation number in the quote!");
return null;
}
string accountName = recipient.Account.AccountName.Replace(" ", "_");
string description = quote.Description.Replace(" ", "_");
return Path.Combine(accountName, $"{DateTime.Today.Year}-{DateTime.Today.Month}-{recipient.LastName}-{description}", $"{quote.QuotationNumber}.pdf");
}
}