This commit is contained in:
@@ -151,57 +151,21 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
if (Subject.Contains("{{") || Body.Contains("{{"))
|
if (Subject.Contains("{{") || Body.Contains("{{"))
|
||||||
{
|
{
|
||||||
|
|
||||||
//fetch the object with viz fields for easy templatization
|
//fetch the object with viz fields for easy templatization
|
||||||
switch (ne.AyaType)
|
switch (ne.AyaType)
|
||||||
{
|
{
|
||||||
case AyaType.Quote:
|
case AyaType.Quote:
|
||||||
{
|
{
|
||||||
var qb = QuoteBiz.GetBiz(ct);
|
var qt = await ct.Quote.AsNoTracking().FirstOrDefaultAsync(z => z.Id == ne.ObjectId);
|
||||||
await qb.QuoteGetAsync(ne.ObjectId, true, false);
|
if (qt == null)
|
||||||
todo figure this regex out, make it a function
|
|
||||||
MatchCollection matches = Regex.Matches(Subject, @"\{{(.|\n)*?\}}", RegexOptions.IgnorePatternWhitespace
|
|
||||||
| RegexOptions.Compiled);
|
|
||||||
foreach (Match KeyMatch in matches)
|
|
||||||
{
|
{
|
||||||
switch (KeyMatch.Value)
|
//maybe deleted, this can't proceed
|
||||||
{
|
throw new ApplicationException($"Unable to make delivery for customer notify event as Quote {ne.Name} was not found during delivery, deleted?");
|
||||||
case "[WorkorderService.Label.ServiceNumber]":
|
|
||||||
sTemplate = sTemplate.Replace(KeyMatch.Value, wonumber);
|
|
||||||
break;
|
|
||||||
case "[O.WorkorderStatus]":
|
|
||||||
if (statpick.Contains(WorkorderStatusID))
|
|
||||||
sTemplate = sTemplate.Replace(KeyMatch.Value, statpick[WorkorderStatusID].Name);
|
|
||||||
else
|
|
||||||
sTemplate = sTemplate.Replace(KeyMatch.Value, "");
|
|
||||||
break;
|
|
||||||
case "[Workorder.Label.CustomerContactName]":
|
|
||||||
sTemplate = sTemplate.Replace(KeyMatch.Value, contact);
|
|
||||||
break;
|
|
||||||
case "[Workorder.Label.CustomerReferenceNumber]":
|
|
||||||
sTemplate = sTemplate.Replace(KeyMatch.Value, cref);
|
|
||||||
break;
|
|
||||||
case "[Region.Label.WBIUrl]":
|
|
||||||
sTemplate = sTemplate.Replace(KeyMatch.Value, r.WBIUrl);
|
|
||||||
break;
|
|
||||||
case "[Client.Label.Name]":
|
|
||||||
sTemplate = sTemplate.Replace(KeyMatch.Value, cl[0].LT_O_Client.Display);
|
|
||||||
break;
|
|
||||||
case "[ClientServiceRequest.Label.Details]":
|
|
||||||
sTemplate = sTemplate.Replace(KeyMatch.Value, csrdetails);
|
|
||||||
break;
|
|
||||||
case "[Workorder.Label.Summary]":
|
|
||||||
sTemplate = sTemplate.Replace(KeyMatch.Value, wosummary);
|
|
||||||
break;
|
|
||||||
case "[ClientServiceRequest.Label.Title]":
|
|
||||||
sTemplate = sTemplate.Replace(KeyMatch.Value, csrtitle);
|
|
||||||
break;
|
|
||||||
//case 1499
|
|
||||||
case "[WorkorderQuote.Label.QuoteNumber]":
|
|
||||||
sTemplate = sTemplate.Replace(KeyMatch.Value, wonumber);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var CustomerName = await ct.Customer.AsNoTracking().Where(x => x.Id == qt.CustomerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||||
|
Subject = SetQuoteTokens(Subject, qt, CustomerName);
|
||||||
|
Body = SetQuoteTokens(Body, qt, CustomerName);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AyaType.WorkOrder:
|
case AyaType.WorkOrder:
|
||||||
@@ -262,7 +226,7 @@ namespace AyaNova.Biz
|
|||||||
var path = (string)lastLogJ["reportfilename"];
|
var path = (string)lastLogJ["reportfilename"];
|
||||||
var FilePath = FileUtil.GetFullPathForTemporaryFile(path);
|
var FilePath = FileUtil.GetFullPathForTemporaryFile(path);
|
||||||
var FileName = FileUtil.StringToSafeFileName(await TranslationBiz.GetTranslationStaticAsync(ne.AyaType.ToString(), subTranslationId, ct) + $"-{ne.Name}.pdf").ToLowerInvariant();
|
var FileName = FileUtil.StringToSafeFileName(await TranslationBiz.GetTranslationStaticAsync(ne.AyaType.ToString(), subTranslationId, ct) + $"-{ne.Name}.pdf").ToLowerInvariant();
|
||||||
await m.SendEmailAsync(deliveryAddress, ne.Subject, ne.Message, ServerGlobalOpsSettingsCache.Notify, FilePath, FileName);
|
await m.SendEmailAsync(deliveryAddress, Subject, Body, ServerGlobalOpsSettingsCache.Notify, FilePath, FileName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case JobStatus.Failed:
|
case JobStatus.Failed:
|
||||||
@@ -300,6 +264,39 @@ namespace AyaNova.Biz
|
|||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string SetQuoteTokens(string TheField, Quote qt, string CustomerName)
|
||||||
|
{
|
||||||
|
MatchCollection matches = Regex.Matches(TheField, @"\{{(.|\n)*?\}}", RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
|
||||||
|
//{{.*?}}
|
||||||
|
foreach (Match KeyMatch in matches)
|
||||||
|
{
|
||||||
|
switch (KeyMatch.Value)
|
||||||
|
{
|
||||||
|
case "{{Customer}}":
|
||||||
|
TheField = TheField.Replace(KeyMatch.Value, CustomerName);
|
||||||
|
break;
|
||||||
|
case "{{QuoteIntroduction}}":
|
||||||
|
TheField = TheField.Replace(KeyMatch.Value, qt.Introduction);
|
||||||
|
break;
|
||||||
|
case "{{WorkOrderCustomerContactName}}":
|
||||||
|
TheField = TheField.Replace(KeyMatch.Value, qt.CustomerContactName);
|
||||||
|
break;
|
||||||
|
case "{{WorkOrderCustomerReferenceNumber}}":
|
||||||
|
TheField = TheField.Replace(KeyMatch.Value, qt.CustomerReferenceNumber);
|
||||||
|
break;
|
||||||
|
case "{{WorkOrderSummary}}":
|
||||||
|
TheField = TheField.Replace(KeyMatch.Value, qt.Notes);
|
||||||
|
break;
|
||||||
|
case "{{QuoteSerialNumber}}":
|
||||||
|
TheField = TheField.Replace(KeyMatch.Value, qt.Serial.ToString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TheField;
|
||||||
|
}
|
||||||
//===
|
//===
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user