From 9d2a9af98aa661cb1cbd12080e2913771e2a3eef Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 21 Apr 2023 22:22:11 +0000 Subject: [PATCH] --- server/biz/SubscriptionBiz.cs | 27 +++++++++++++-------------- server/models/SubscriptionItem.cs | 2 ++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/server/biz/SubscriptionBiz.cs b/server/biz/SubscriptionBiz.cs index ff40ac9..20d6ac6 100644 --- a/server/biz/SubscriptionBiz.cs +++ b/server/biz/SubscriptionBiz.cs @@ -304,7 +304,7 @@ namespace Sockeye.Biz if (!ReportRenderManager.KeepGoing(jobId)) return null; //var subId = .Select(z => z.SubscriptionId).FirstOrDefaultAsync(); var subItem = await ct.SubscriptionItem.AsNoTracking().Where(z => z.Id == batchId).FirstOrDefaultAsync(); - await PopulateItemVizFields(subItem, 0); + await PopulateItemVizFields(subItem); batchResults.Add(subItem); } @@ -336,7 +336,7 @@ namespace Sockeye.Biz foreach (var item in o.Items)//some subscriptions have a bunch of the same monthly or yearly raven user in them so this will save in that case { - await PopulateItemVizFields(item, o.CustomerId); + await PopulateItemVizFields(item, o); // if (!vc.Has("productname", item.ProductId)) // { // var productInfo = await ct.Product.AsNoTracking().Where(x => x.Id == item.ProductId).FirstOrDefaultAsync(); @@ -352,23 +352,22 @@ namespace Sockeye.Biz } //populate viz fields from provided object - private async Task PopulateItemVizFields(SubscriptionItem o, long CustomerId) + private async Task PopulateItemVizFields(SubscriptionItem o, Subscription sub = null) { - if (CustomerId == 0) - CustomerId = await ct.Subscription.Where(z => z.Id == o.SubscriptionId).Select(z => z.CustomerId).FirstOrDefaultAsync(); + if (sub == null) + sub = await ct.Subscription.AsNoTracking().Where(z => z.Id == o.SubscriptionId).FirstOrDefaultAsync(); + o.SubscriptionEmailViz = sub.FetchEmail; - if (CustomerId != 0) + if (!vc.Has("customername", sub.CustomerId)) { - if (!vc.Has("customername", CustomerId)) - { - var custInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == CustomerId).FirstOrDefaultAsync(); - vc.Add(custInfo.Name, "customername", CustomerId); - vc.Add(custInfo.EmailAddress, "customeremail", CustomerId); - } - o.CustomerViz = vc.Get("customername", CustomerId); - o.CustomerEmailViz = vc.Get("customeremail", CustomerId); + var custInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == sub.CustomerId).FirstOrDefaultAsync(); + vc.Add(custInfo.Name, "customername", sub.CustomerId); + vc.Add(custInfo.EmailAddress, "customeremail", sub.CustomerId); } + o.CustomerViz = vc.Get("customername", sub.CustomerId); + o.CustomerEmailViz = vc.Get("customeremail", sub.CustomerId); + if (!vc.Has("productname", o.ProductId)) { diff --git a/server/models/SubscriptionItem.cs b/server/models/SubscriptionItem.cs index 7298e3d..6ed3099 100644 --- a/server/models/SubscriptionItem.cs +++ b/server/models/SubscriptionItem.cs @@ -43,6 +43,8 @@ namespace Sockeye.Models public string CustomerViz { get; set; } [NotMapped] public string CustomerEmailViz { get; set; } + [NotMapped] + public string SubscriptionEmailViz { get; set; } public List Tags { get; set; } = new List();