50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using Gremlin_BlazorServer.Data.EntityClasses;
|
|
|
|
namespace Gremlin_BlazorServer.Services;
|
|
|
|
public class HostingService
|
|
{
|
|
private readonly IWebHostEnvironment hostingEnvironment;
|
|
|
|
public HostingService(IWebHostEnvironment newHostingEnvironment) => hostingEnvironment = newHostingEnvironment;
|
|
|
|
public Quote SetPath(Quote quote)
|
|
{
|
|
if (quote.Recipient?.Account?.AccountName == null || quote.Description == null)
|
|
{
|
|
Console.WriteLine("No acount or desciption in the quote!");
|
|
return quote;
|
|
}
|
|
|
|
string accountName = quote.Recipient.Account.AccountName.Replace(" ", "_");
|
|
string description = quote.Description.Replace(" ", "_");
|
|
|
|
quote.Path = Path.Combine(
|
|
hostingEnvironment.WebRootPath,
|
|
"quotes",
|
|
accountName,
|
|
$"{DateTime.Today.Year}-{DateTime.Today.Month}-{quote.Recipient?.LastName}-{description}"
|
|
);
|
|
|
|
return quote;
|
|
}
|
|
|
|
public static string? GetPdfUrl(Quote quote)
|
|
{
|
|
if (quote.Path == null || quote.QuotationNumber == null || quote.Recipient?.Account?.AccountName == null || quote.Description == null)
|
|
{
|
|
Console.WriteLine("No path, account, description or quotation number in the quote!");
|
|
return null;
|
|
}
|
|
|
|
string accountName = quote.Recipient.Account.AccountName.Replace(" ", "_");
|
|
string description = quote.Description.Replace(" ", "_");
|
|
|
|
return Path.Combine(
|
|
accountName,
|
|
$"{DateTime.Today.Year}-{DateTime.Today.Month}-{quote.Recipient?.LastName}-{description}",
|
|
$"{quote.QuotationNumber}.pdf"
|
|
);
|
|
}
|
|
}
|