From 61741c1a945bbdf7eedceae822bb20f740d47014 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 13 Jan 2023 22:30:17 +0000 Subject: [PATCH] --- server/biz/TrialLicenseRequestBiz.cs | 62 ++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/server/biz/TrialLicenseRequestBiz.cs b/server/biz/TrialLicenseRequestBiz.cs index d67e321..d6a4dbd 100644 --- a/server/biz/TrialLicenseRequestBiz.cs +++ b/server/biz/TrialLicenseRequestBiz.cs @@ -133,16 +133,13 @@ namespace Sockeye.Biz if (HasErrors) return null; - //Automated processint - //## ------------------ DEFAULT NOTIFICATIONS TO CUSTOMER ---------------- - //RavenTrialApproved (which sends pending manual generation message) and RavenTrialRejected messages are sent in this block - Sockeye.Api.Controllers.NotifyController.NotifyDirectSMTP notifyDirectSMTP = null; + //IF WE HAVE APPROVED A REQUEST THEN GENERATE TRIAL LICENSE, NOTIFY USER if (dbObject.Status == TrialRequestStatus.AwaitingApproval && putObject.Status == TrialRequestStatus.Approved) { //APPROVED, generate and save key to be approved for release by us putObject.Processed = DateTime.UtcNow; License l = new License(); - l.Active = false;//not released to customer until we set to active and save + l.Active = true;//Released for pickup l.DbId = putObject.DbId; l.PGroup = putObject.PGroup; l.TrialMode = true; @@ -161,8 +158,51 @@ namespace Sockeye.Biz l.MaxDataGB = RavenKeyFactory.TRIAL_KEY_SUBSCRIPTION_MAX_DATA_GB; } + LicenseBiz licenseBiz = LicenseBiz.GetBiz(ct); + var newLicense = await licenseBiz.CreateAsync(l); + if (newLicense == null) + { + //need to alert on error here + AddError(ApiErrorCode.INVALID_OPERATION, "generalerror", $"ERROR creating trial license on approved trial request:{licenseBiz.GetErrorsAsString}"); + return null; + } + + //all is well, new license was created + putObject.LicenseId = newLicense.Id; + + //Notify User + /* + var body = $"Your trial license request has been approved.\r\nThe license will fetch and install automatically shortly or you can fetch it now in the License form menu."; + //send confirmation email + RfMail.SendMessage("support@ayanova.com", trial.Email, "AyaNova trial request approved", body, false); + + */ + var notifyDirectSMTP = new Sockeye.Api.Controllers.NotifyController.NotifyDirectSMTP() + { + ToAddress = putObject.Email, + Subject = "AyaNova trial request approved",//todo move to global settings + TextBody = ServerGlobalBizSettings.Cache.RavenTrialApproved + }; + + IMailer m = Sockeye.Util.ServiceProviderProvider.Mailer; + try + { + await m.SendEmailAsync(notifyDirectSMTP.ToAddress, notifyDirectSMTP.Subject, notifyDirectSMTP.TextBody, ServerGlobalOpsSettingsCache.Notify, null, null, null); + await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, notifyDirectSMTP.ObjectId, notifyDirectSMTP.SockType, SockEvent.DirectSMTP, $"\"{notifyDirectSMTP.Subject}\"->{notifyDirectSMTP.ToAddress}"), ct); + } + catch (Exception ex) + { + var err = "TrialLicenseRequest sending approved email: SMTP direct message failed"; + await NotifyEventHelper.AddOpsProblemEvent(err, ex); + AddError(ApiErrorCode.API_SERVER_ERROR, null, ExceptionUtil.ExtractAllExceptionMessages(ex)); + return null; + + } + } + + if (dbObject.Status == TrialRequestStatus.AwaitingApproval && putObject.Status == TrialRequestStatus.Rejected) { //REJECTED, send email @@ -170,18 +210,16 @@ namespace Sockeye.Biz } - - ct.Replace(dbObject, putObject); try { + + //first save request *then* license if all is well + await ct.SaveChangesAsync(); - //EMAIL? - if (notifyDirectSMTP != null) - { - //send an email - } + + } catch (DbUpdateConcurrencyException)