public bool LogAsync(string message, Exception exception, LogLevel logLevel, LogNotification logNotification) { throw new NotImplementedException(); }
private IOperation BuildShellOperation() { var aboutNotification = new AboutNotification(context.AppConfig, text, uiFactory); var audio = new Audio(context.Settings.Audio, ModuleLogger(nameof(Audio))); var keyboard = new Keyboard(ModuleLogger(nameof(Keyboard))); var logNotification = new LogNotification(logger, text, uiFactory); var operation = new ShellOperation( actionCenter, audio, aboutNotification, context, keyboard, logger, logNotification, powerSupply, systemInfo, taskbar, taskview, text, uiFactory, wirelessAdapter); context.Activators.Add(new ActionCenterKeyboardActivator(ModuleLogger(nameof(ActionCenterKeyboardActivator)), nativeMethods)); context.Activators.Add(new ActionCenterTouchActivator(ModuleLogger(nameof(ActionCenterTouchActivator)), nativeMethods)); context.Activators.Add(new TaskviewKeyboardActivator(ModuleLogger(nameof(TaskviewKeyboardActivator)), nativeMethods)); context.Activators.Add(new TerminationActivator(ModuleLogger(nameof(TerminationActivator)), nativeMethods)); return(operation); }
private static void Fatal(string message, System.Exception exception, System.Type ownerType, string loggerName) { ILogger logger = null; if (!Log.Enabled) { return; } if (ownerType != null) { logger = LoggerManager.GetLogger(Assembly.GetCallingAssembly(), ownerType); } else { logger = LoggerManager.GetLogger(Assembly.GetCallingAssembly(), loggerName); } if (logger != null) { if (exception != null) { logger.Log(typeof(Log).ToString(), Level.FATAL, message, exception); } else { logger.Log(typeof(Log).ToString(), Level.FATAL, message, null); } if (SystemCount.LoggingFatalsLogged != null) { SystemCount.LoggingFatalsLogged.Increment(1L); } } LogNotification.RaiseNotification(LogNotificationLevel.Fatal, message, exception); }
private static void Warn(string message, System.Exception exception, object owner, string loggerName) { ILogger logger = null; if (!Log.Enabled) { return; } if (owner != null) { logger = LoggerManager.GetLogger(Assembly.GetCallingAssembly(), owner.GetType()); } else { logger = LoggerManager.GetLogger(Assembly.GetCallingAssembly(), loggerName); } if (logger != null) { if (exception != null) { logger.Log(typeof(Log).ToString(), Level.WARN, message, exception); } else { logger.Log(typeof(Log).ToString(), Level.WARN, message, null); } if (SystemCount.LoggingWarningsLogged != null) { SystemCount.LoggingWarningsLogged.Increment(1L); } } LogNotification.RaiseNotification(LogNotificationLevel.Warning, message, exception); }
private static void Info(string message, object owner, string loggerName) { ILogger logger = null; if (!Log.Enabled) { return; } if (owner != null) { logger = LoggerManager.GetLogger(Assembly.GetCallingAssembly(), owner.GetType()); } else { logger = LoggerManager.GetLogger(Assembly.GetCallingAssembly(), loggerName); } if (logger != null) { logger.Log(typeof(Log).ToString(), Level.INFO, message, null); if (SystemCount.LoggingInformationsLogged != null) { SystemCount.LoggingInformationsLogged.Increment(1L); } } LogNotification.RaiseNotification(LogNotificationLevel.Info, message); }
public bool Log(string message, Exception exception, LogLevel logLevel, LogNotification logNotification, LogParameter logParameter) { throw new NotImplementedException(); }
public void Log(SeverityLevel level, object text) { var message = new LogMessage(level, text?.ToString()); foreach (var provider in _providers) { provider.Log(message); } LogNotification?.Invoke(message); }
/// <summary> /// Logs a single fatal message. /// </summary> /// <param name="message"> /// The message. /// </param> /// <param name="exception"> /// The exception. /// </param> /// <param name="ownerType"> /// Type of the owner. /// </param> public static void SingleFatal(string message, System.Exception exception, System.Type ownerType) { Assert.ArgumentNotNull(message, "message"); Assert.ArgumentNotNull(ownerType, "ownerType"); if (!Log.Enabled || Log.Singles == null || Log.Singles.ContainsKey(message)) { return; } Log.Fatal(string.Format("SINGLE MSG: {0}", message), exception, ownerType); Log.Singles.Add(message, string.Empty); LogNotification.RaiseNotification(LogNotificationLevel.Fatal, message, exception); }
public void MustCloseWindowWhenTerminating() { var window = new Mock <IWindow>(); var sut = new LogNotification(logger.Object, text.Object, uiFactory.Object); uiFactory.Setup(u => u.CreateLogWindow(It.IsAny <ILogger>())).Returns(window.Object); sut.Activate(); sut.Terminate(); window.Verify(w => w.Close()); }
public void MustOpenOnlyOneWindow() { var window = new Mock <IWindow>(); var sut = new LogNotification(logger.Object, text.Object, uiFactory.Object); uiFactory.Setup(u => u.CreateLogWindow(It.IsAny <ILogger>())).Returns(window.Object); sut.Activate(); sut.Activate(); sut.Activate(); sut.Activate(); sut.Activate(); uiFactory.Verify(u => u.CreateLogWindow(It.IsAny <ILogger>()), Times.Once); window.Verify(u => u.Show(), Times.Once); window.Verify(u => u.BringToForeground(), Times.Exactly(4)); }
public ActionResult UnlockUser(DeleteUserViewModel model) { using (DBModel db = new DBModel()) { try { var getUserToUnlock = db.AspNetUsers.SingleOrDefault(c => c.Id == model.UserId); var _action = "UnlockUser"; getUserToUnlock.AccessFailedCount = 0; getUserToUnlock.LockoutEndDateUtc = null; getUserToUnlock.Status = 1; var recordSaved = db.SaveChanges(); if (recordSaved > 0) { //Send email notification to user var callbackUrl = Url.Action("ResetAccount", "Account", null, Request.Url.Scheme); var ApplicationApprovedEmailMessage = "Dear " + getUserToUnlock.CompanyName + ", <br/><br/> Your account has been unlocked. <br/>" + "<a href=" + callbackUrl + "> Click here to reset your password. </a> <br/><br/>" + "Kind Regards, <br /> Global Markets Digital Team <br/><img src=\"/Content/images/EmailSignature.png\"/>"; var ApplicationCompleteEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, getUserToUnlock.Email, "Account Unlocked", ApplicationApprovedEmailMessage); if (ApplicationCompleteEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, ApplicationApprovedEmailMessage, getUserToUnlock.Email, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, ApplicationApprovedEmailMessage, getUserToUnlock.Email, _action); } return(Json("success", JsonRequestBehavior.AllowGet)); } else { return(Json("Error! Unable to unlock user", JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } } }
public JsonResult ApproveNomination(ConfirmApproveViewModel model, HttpPostedFileBase inputFile) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { using (DBModel db = new DBModel()) { var currentUserId = User.Identity.GetUserId(); var _userDetails = db.AspNetUsers.SingleOrDefault(e => e.Id == currentUserId); var _action = "ApproveNomination"; //Upload Signature if (inputFile != null) { string pic = DateTime.Now.ToString("yyyyMMdd") + currentUserId + System.IO.Path.GetFileName(inputFile.FileName); string path = System.IO.Path.Combine(Server.MapPath("~/Content/images/signatures/"), pic); // Upload file inputFile.SaveAs(path); //Save File name to Database var SignatoryToUpdate = db.ClientSignatories.First(c => c.EmailAddress == _userDetails.Email && c.CompanyID == model.CompanyID); SignatoryToUpdate.Signature = pic; SignatoryToUpdate.UserAccountID = _userDetails.Id; SignatoryToUpdate.PhoneNumber = model.VerifyPhone; //Update phone number db.SaveChanges(); } //Check if signatory is also an authorized representative var getUserInfo = db.AspNetUsers.SingleOrDefault(c => c.Id == currentUserId); var signatoryIsARepresentative = db.DesignatedUsers.Any(c => c.Email == getUserInfo.Email && c.CompanyID == model.CompanyID); if (signatoryIsARepresentative) { var signatoryClientId = db.ClientSignatories.First(c => c.UserAccountID == currentUserId); //Update representative's signature var RepresentativeToUpdate = db.DesignatedUsers.First(c => c.Email == signatoryClientId.EmailAddress && c.CompanyID == model.CompanyID); RepresentativeToUpdate.Signature = signatoryClientId.Signature; RepresentativeToUpdate.Mobile = model.VerifyPhone; //Update phone number db.SaveChanges(); //Log Signatory Approval try { var LogApproval = db.SignatoryApprovals.Create(); LogApproval.ApplicationID = model.ApplicationID; LogApproval.SignatoryID = signatoryClientId.Id; LogApproval.AcceptedTerms = model.terms; LogApproval.DateApproved = DateTime.Now; db.SignatoryApprovals.Add(LogApproval); var savedItem = db.SaveChanges(); if (savedItem > 0) { //Log signatory approval var nominationToUpdate = db.ApplicationNominations.SingleOrDefault(c => c.NomineeEmail == signatoryClientId.EmailAddress && c.ApplicationID == model.ApplicationID && c.CompanyID == model.CompanyID && c.NominationType == 1); nominationToUpdate.NominationStatus = 1; db.SaveChanges(); } } catch (Exception) { return(Json("Error! Unable to log signatory approval", JsonRequestBehavior.AllowGet)); } //Log Representative Approval try { var userClientId = db.DesignatedUsers.First(c => c.Email == getUserInfo.Email && c.CompanyID == model.CompanyID); var LogDesignatedUserApproval = db.DesignatedUserApprovals.Create(); LogDesignatedUserApproval.ApplicationID = model.ApplicationID; LogDesignatedUserApproval.UserID = userClientId.Id; LogDesignatedUserApproval.AcceptedTerms = model.terms; LogDesignatedUserApproval.DateApproved = DateTime.Now; db.DesignatedUserApprovals.Add(LogDesignatedUserApproval); var savedItem = db.SaveChanges(); if (savedItem > 0) { //Log signatory approval var repNominationToUpdate = db.ApplicationNominations.SingleOrDefault(c => c.NomineeEmail == userClientId.Email && c.ApplicationID == model.ApplicationID && c.CompanyID == model.CompanyID && c.NominationType == 2); repNominationToUpdate.NominationStatus = 1; db.SaveChanges(); } } catch (Exception) { return(Json("Error! Unable to log representative approval", JsonRequestBehavior.AllowGet)); } //Update application Id var ApplicationUpdate = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID && c.CompanyID == model.CompanyID); if (ApplicationUpdate != null) { try { var SignatoryApprovals = ApplicationUpdate.SignatoriesApproved; var UsersApprovals = ApplicationUpdate.UsersApproved; ApplicationUpdate.SignatoriesApproved = SignatoryApprovals + 1; ApplicationUpdate.UsersApproved = UsersApprovals + 1; ApplicationUpdate.SignatoriesDateApproved = DateTime.Now; ApplicationUpdate.UsersDateApproved = DateTime.Now; db.SaveChanges(); } catch (Exception) { return(Json("Error! Unable to update application details", JsonRequestBehavior.AllowGet)); } //Check if all signatories have approved if (ApplicationUpdate.SignatoriesApproved >= ApplicationUpdate.Signatories) { //Send Emails to representatives for approval excluding the existing users foreach (var email in db.DesignatedUsers.Where(c => c.ClientID == signatoryClientId.ClientID && c.CompanyID == model.CompanyID).ToList()) { var emailExists = db.AspNetUsers.Any(x => x.Email.ToLower() == email.Email.ToLower()); if (!emailExists) { //1. Update Designated User with OTP to Login var _OTPCode = OTPGenerator.GetUniqueKey(6); string OTPCode = Shuffle.StringMixer(_OTPCode); var UserToUpdate = db.DesignatedUsers.SingleOrDefault(c => c.Email == email.Email && c.CompanyID == model.CompanyID); UserToUpdate.OTP = Functions.GenerateMD5Hash(OTPCode); UserToUpdate.DateCreated = DateTime.Now; db.SaveChanges(); //2. Send Email To Representatives with OTP var callbackUrl = Url.Action("DesignatedUserConfirmation", "Account", null, Request.Url.Scheme); string EmailBodyRep = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/RepresentativeNomination.html"))) { EmailBodyRep = reader.ReadToEnd(); } EmailBodyRep = EmailBodyRep.Replace("{RepresentativeName}", email.Surname); EmailBodyRep = EmailBodyRep.Replace("{ActivationCode}", OTPCode); EmailBodyRep = EmailBodyRep.Replace("{URL}", callbackUrl); var EmailToRepresentative = MailHelper.SendMailMessage(MailHelper.EmailFrom, email.Email.ToLower(), "Authorized Representative Confirmation", EmailBodyRep); if (EmailToRepresentative == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } } else { //Send Email To Representatives without OTP var callbackUrl = Url.Action("Index", "Home", null, Request.Url.Scheme); string EmailBodyRep = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ExistingRepresentativeNomination.html"))) { EmailBodyRep = reader.ReadToEnd(); } EmailBodyRep = EmailBodyRep.Replace("{RepresentativeName}", email.Surname); EmailBodyRep = EmailBodyRep.Replace("{URL}", callbackUrl); var EmailToRepresentative = MailHelper.SendMailMessage(MailHelper.EmailFrom, email.Email.ToLower(), "Authorized Representative Confirmation", EmailBodyRep); if (EmailToRepresentative == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } } } } } else { return(Json("Error! Unable to update representative details!", JsonRequestBehavior.AllowGet)); } //Send email to signatory after approval string EmailBody = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/SignatoryRepresentativeApproval.html"))) { EmailBody = reader.ReadToEnd(); } EmailBody = EmailBody.Replace("{Othernames}", signatoryClientId.OtherNames); EmailBody = EmailBody.Replace("{CompanyName}", model.CompanyName); var SendRegistrationCompleteEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, signatoryClientId.EmailAddress, "Signatory/Authorized Representative Approval", EmailBody); if (SendRegistrationCompleteEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody, signatoryClientId.EmailAddress, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody, signatoryClientId.EmailAddress, _action); } //Send email to company string EmailBody2 = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ClientConfirmationApproval.html"))) { EmailBody2 = reader.ReadToEnd(); } EmailBody2 = EmailBody2.Replace("{Othernames}", model.CompanySurname); EmailBody2 = EmailBody2.Replace("{ApproversName}", signatoryClientId.Surname + " " + signatoryClientId.OtherNames); var SendClientConfirmationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, model.CompanyEmail, "Signatory/Authorized Representative Approval", EmailBody2); if (SendClientConfirmationEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } } //When signatory is not in representative list else { var signatoryClientId = db.ClientSignatories.First(c => c.EmailAddress == _userDetails.Email && c.CompanyID == model.CompanyID); //Log Signatory Approval try { var LogApproval = db.SignatoryApprovals.Create(); LogApproval.ApplicationID = model.ApplicationID; LogApproval.SignatoryID = signatoryClientId.Id; LogApproval.AcceptedTerms = model.terms; LogApproval.DateApproved = DateTime.Now; db.SignatoryApprovals.Add(LogApproval); var savedItem = db.SaveChanges(); if (savedItem > 0) { var nominationToUpdate = db.ApplicationNominations.SingleOrDefault(c => c.NomineeEmail == signatoryClientId.EmailAddress && c.ApplicationID == model.ApplicationID && c.CompanyID == model.CompanyID && c.NominationType == 1); nominationToUpdate.NominationStatus = 1; db.SaveChanges(); } } catch (Exception) { return(Json("Error! Unable to log signatory approval", JsonRequestBehavior.AllowGet)); } //Update application Id var ApplicationUpdate = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID); if (ApplicationUpdate != null) { try { var SignatoryApprovals = ApplicationUpdate.SignatoriesApproved; ApplicationUpdate.SignatoriesApproved = SignatoryApprovals + 1; ApplicationUpdate.SignatoriesDateApproved = DateTime.Now; db.SaveChanges(); } catch (Exception) { return(Json("Error! Unable to update application details", JsonRequestBehavior.AllowGet)); } //Check if all signatories have approved if (ApplicationUpdate.SignatoriesApproved >= ApplicationUpdate.Signatories) { //Send Emails to representatives for approval excluding the existing users and registered Clients var _dontSendEmail = db.RegisteredClients.Select(x => x.EmailAddress).ToList(); foreach (var email in db.DesignatedUsers.Where(c => c.ClientID == signatoryClientId.ClientID && c.CompanyID == model.CompanyID && !_dontSendEmail.Contains(c.Email)).ToList()) { var emailExists = db.AspNetUsers.Any(x => x.Email.ToLower() == email.Email.ToLower()); if (!emailExists) { //1. Update Designated User with OTP to Login var _OTPCode = OTPGenerator.GetUniqueKey(6); string OTPCode = Shuffle.StringMixer(_OTPCode); var UserToUpdate = db.DesignatedUsers.SingleOrDefault(c => c.Email == email.Email && c.CompanyID == model.CompanyID); UserToUpdate.OTP = Functions.GenerateMD5Hash(OTPCode); UserToUpdate.DateCreated = DateTime.Now; db.SaveChanges(); //2. Send Email To Representatives with OTP var callbackUrl = Url.Action("DesignatedUserConfirmation", "Account", null, Request.Url.Scheme); string EmailBodyRep = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/RepresentativeNomination.html"))) { EmailBodyRep = reader.ReadToEnd(); } EmailBodyRep = EmailBodyRep.Replace("{RepresentativeName}", email.Surname); EmailBodyRep = EmailBodyRep.Replace("{ActivationCode}", OTPCode); EmailBodyRep = EmailBodyRep.Replace("{URL}", callbackUrl); var EmailToRepresentative = MailHelper.SendMailMessage(MailHelper.EmailFrom, email.Email.ToLower(), "Authorized Representative Confirmation", EmailBodyRep); if (EmailToRepresentative == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } } else { //Check if he has already approved var userHasApproved = db.ApplicationNominations.Any(c => c.ApplicationID == model.ApplicationID && c.CompanyID == model.CompanyID && c.NomineeEmail.ToLower() == email.Email.ToLower() && c.NominationType == 2 && c.NominationStatus == 1); if (!userHasApproved) { //Send Email To Representatives without OTP var callbackUrl = Url.Action("Index", "Home", null, Request.Url.Scheme); string EmailBodyRep = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ExistingRepresentativeNomination.html"))) { EmailBodyRep = reader.ReadToEnd(); } EmailBodyRep = EmailBodyRep.Replace("{RepresentativeName}", email.Surname); EmailBodyRep = EmailBodyRep.Replace("{URL}", callbackUrl); var EmailToRepresentative = MailHelper.SendMailMessage(MailHelper.EmailFrom, email.Email.ToLower(), "Authorized Representative Confirmation", EmailBodyRep); if (EmailToRepresentative == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } } } } } } else { return(Json("Unable to Update Details!", JsonRequestBehavior.AllowGet)); } //Send email to signatory string EmailBody = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/SignatoryApproval.html"))) { EmailBody = reader.ReadToEnd(); } EmailBody = EmailBody.Replace("{Othernames}", signatoryClientId.OtherNames); EmailBody = EmailBody.Replace("{CompanyName}", model.CompanyName); var SendRegistrationCompleteEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, signatoryClientId.EmailAddress, "Signatory Approval", EmailBody); if (SendRegistrationCompleteEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody, signatoryClientId.EmailAddress, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody, signatoryClientId.EmailAddress, _action); } //Send email to company string EmailBody2 = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ClientConfirmationApproval.html"))) { EmailBody2 = reader.ReadToEnd(); } EmailBody2 = EmailBody2.Replace("{Othernames}", model.CompanySurname); EmailBody2 = EmailBody2.Replace("{ApproversName}", signatoryClientId.Surname + " " + signatoryClientId.OtherNames); var SendClientConfirmationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, model.CompanyEmail, "Signatory Approval", EmailBody2); if (SendClientConfirmationEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } } } return(Json("success", JsonRequestBehavior.AllowGet)); } else { return(Json("Model Invalid! " + errors + " ", JsonRequestBehavior.AllowGet)); } }
public JsonResult ApproveApplication(AdminApproveViewModel model) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { using (DBModel db = new DBModel()) { //1. Update application Details var currentUserId = User.Identity.GetUserId(); var ApplicationUpdate = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID); var CompanyDetails = db.ClientCompanies.SingleOrDefault(s => s.Id == ApplicationUpdate.CompanyID); var _action = "ApproveApplication"; if (ApplicationUpdate != null) { try { //2. Update application status ApplicationUpdate.OPSApproved = true; ApplicationUpdate.OPSDateApproved = DateTime.Now; ApplicationUpdate.OPSWhoApproved = currentUserId; ApplicationUpdate.OPSApprovalStatus = 1; ApplicationUpdate.OPSComments = model.Comments; var savedApplicationDetails = db.SaveChanges(); if (savedApplicationDetails > 0) { //3. Send email notification to Poa for approval var DDUserRole = (from p in db.AspNetUserRoles join e in db.AspNetUsers on p.UserId equals e.Id where p.RoleId == "1f477b75-8a56-4662-b4d1-48551bed6111" && e.Status == 1 select new { EmailID = e.Email }).ToList(); foreach (var email in DDUserRole) { var DDMessageBody = "Dear Team <br/><br/> Kindly note that the following client's application has been approved by the Operations Team. <br/>" + "Company Name: " + CompanyDetails.CompanyName + ", Company Email: " + CompanyDetails.BusinessEmailAddress + " " + "<br/><br/> Kind Regards,<br/><img src=\"https://e-documents.stanbicbank.co.ke/Content/images/EmailSignature.png\"/>"; var SendDDNotificationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, email.EmailID, "Ops Approved Application", DDMessageBody); if (SendDDNotificationEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, DDMessageBody, email.EmailID, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, DDMessageBody, email.EmailID, _action); } } } } catch (Exception ex) { throw (ex); } } else { return(Json("Unable to approve application!", JsonRequestBehavior.AllowGet)); } } return(Json("success", JsonRequestBehavior.AllowGet)); } else { return(Json("Model Invalid! " + errors + " ", JsonRequestBehavior.AllowGet)); } }
public JsonResult ApproveApplication(AdminApproveViewModel model) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { using (DBModel db = new DBModel()) { //Update application Details var currentUserId = User.Identity.GetUserId(); var ApplicationUpdate = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID); var _action = "ApproveApplication"; if (ApplicationUpdate != null) { try { ApplicationUpdate.POAApproved = true; ApplicationUpdate.POADateApproved = DateTime.Now; ApplicationUpdate.POAWhoApproved = currentUserId; ApplicationUpdate.POAApprovalStatus = 1; ApplicationUpdate.POAComments = model.Comments; db.SaveChanges(); //Send Email to Client string EmailBody = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ApplicationApproved.html"))) { EmailBody = reader.ReadToEnd(); } EmailBody = EmailBody.Replace("{CompanyName}", model.CompanyName); var SendRegistrationCompleteEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, model.CompanyEmail, "Application Approved", EmailBody); if (SendRegistrationCompleteEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody, model.CompanyEmail, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody, model.CompanyEmail, _action); } } catch (Exception ex) { throw (ex); } } else { return(Json("Error! Unable to approve application!", JsonRequestBehavior.AllowGet)); } } return(Json("success", JsonRequestBehavior.AllowGet)); } else { return(Json("Model Invalid! " + errors + " ", JsonRequestBehavior.AllowGet)); } }
public JsonResult DeclineApplication(DeclineApplicationViewModel model) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { using (DBModel db = new DBModel()) { //Update application Details var currentUserId = User.Identity.GetUserId(); var ApplicationUpdate = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationId); var ClientDetails = db.RegisteredClients.SingleOrDefault(s => s.Id == ApplicationUpdate.ClientID); var CompanyDetails = db.ClientCompanies.SingleOrDefault(s => s.Id == ApplicationUpdate.CompanyID); var _action = "DeclineApplication"; if (ApplicationUpdate != null) { try { //1. Update application status ApplicationUpdate.OPSDeclined = true; ApplicationUpdate.OPSDateApproved = DateTime.Now; ApplicationUpdate.OPSWhoDeclined = currentUserId; ApplicationUpdate.OPSApprovalStatus = 4; ApplicationUpdate.Status = 4; ApplicationUpdate.OPSComments = model.Comments; var deleteApplication = db.SaveChanges(); //2. Mark HasApplication False for Client Company var updateClientCompany = db.ClientCompanies.SingleOrDefault(c => c.Id == ApplicationUpdate.CompanyID); updateClientCompany.HasApplication = false; db.SaveChanges(); //3. Delete Signatories db.ClientSignatories.RemoveRange(db.ClientSignatories.Where(c => c.ClientID == ClientDetails.Id && c.CompanyID == ApplicationUpdate.CompanyID)); var deleteSignatories = db.SaveChanges(); //4. Delete Representatives db.DesignatedUsers.RemoveRange(db.DesignatedUsers.Where(c => c.ClientID == ClientDetails.Id && c.CompanyID == ApplicationUpdate.CompanyID)); var deleteUsers = db.SaveChanges(); //5. Delete Settlement Accounts db.ClientSettlementAccounts.RemoveRange(db.ClientSettlementAccounts.Where(c => c.ClientID == ClientDetails.Id && c.CompanyID == ApplicationUpdate.CompanyID)); db.SaveChanges(); if (deleteApplication > 0 && deleteUsers > 0 && deleteSignatories > 0) { //6. Send email notification to Client Company string EmailBody = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ApplicationDeclined.html"))) { EmailBody = reader.ReadToEnd(); } EmailBody = EmailBody.Replace("{CompanyName}", CompanyDetails.CompanyName); var SendRegistrationCompleteEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, ClientDetails.EmailAddress, "Application Declined", EmailBody); if (SendRegistrationCompleteEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody, ClientDetails.EmailAddress, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody, ClientDetails.EmailAddress, _action); } //7. Send email notification to Digital Desk var DDUserRole = (from p in db.AspNetUserRoles join e in db.AspNetUsers on p.UserId equals e.Id where p.RoleId == "03d5e1e3-a8a9-441e-9122-30c3aafccccc" && e.Status == 1 select new { EmailID = e.Email }).ToList(); foreach (var email in DDUserRole) { var DDMessageBody = "Dear Team <br/><br/> Kindly note that the following client's application has been declined by POA. <br/>" + "Company Name: " + ClientDetails.Surname + ", Company Email: " + ClientDetails.EmailAddress + ", Company PhoneNumber: " + ClientDetails.PhoneNumber + " " + "<br/><br/> Kind Regards,<br/><img src=\"https://e-documents.stanbicbank.co.ke/Content/images/EmailSignature.png\"/>"; var SendDDNotificationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, email.EmailID, "Declined Application - Client: " + ClientDetails.Surname + " ", DDMessageBody); if (SendDDNotificationEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, DDMessageBody, email.EmailID, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, DDMessageBody, email.EmailID, _action); } } return(Json("success", JsonRequestBehavior.AllowGet)); } else { return(Json("Unable to update application details", JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { throw (ex); } } else { return(Json("No application details to update", JsonRequestBehavior.AllowGet)); } } } else { return(Json("Model Invalid! " + errors + " ", JsonRequestBehavior.AllowGet)); } }
public void MustNotFailToTerminateIfNotStarted() { var sut = new LogNotification(logger.Object, text.Object, uiFactory.Object); sut.Terminate(); }
public JsonResult DeclineNomination(UserDeclineNominationViewModel model, HttpPostedFileBase inputFile) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { //Upload Signature using (DBModel db = new DBModel()) { var currentUserId = User.Identity.GetUserId(); var userClientId = db.DesignatedUsers.First(c => c.UserAccountID == currentUserId && c.CompanyID == model.CompanyID); var _action = "RepresentativeDeclineNomination"; //Log approval //Upload Signature if (inputFile != null) { string pic = DateTime.Now.ToString("yyyyMMdd") + currentUserId + System.IO.Path.GetFileName(inputFile.FileName); string path = System.IO.Path.Combine(Server.MapPath("~/Content/images/signatures/"), pic); // Upload file inputFile.SaveAs(path); //Save File name to Database //Update Representative Details var DesignatedUserToUpdate = db.DesignatedUsers.FirstOrDefault(c => c.UserAccountID == currentUserId && c.CompanyID == model.CompanyID); DesignatedUserToUpdate.Signature = pic; DesignatedUserToUpdate.Mobile = model.VerifyPhone; db.SaveChanges(); } //Log Approval var LogApproval = db.DesignatedUserApprovals.Create(); LogApproval.ApplicationID = model.ApplicationID; LogApproval.UserID = userClientId.Id; LogApproval.DateApproved = DateTime.Now; LogApproval.Comments = model.Comments; LogApproval.Status = 4; db.DesignatedUserApprovals.Add(LogApproval); var savedItem = db.SaveChanges(); if (savedItem > 0) { //Log signatory approval var nominationToUpdate = db.ApplicationNominations.SingleOrDefault(c => c.NomineeEmail == userClientId.Email && c.ApplicationID == model.ApplicationID && c.CompanyID == model.CompanyID && c.NominationType == 2); nominationToUpdate.NominationStatus = 2; db.SaveChanges(); } //Update application Id var ApplicationUpdate = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID); var Approvals = ApplicationUpdate.UsersApproved; if (ApplicationUpdate != null) { try { ApplicationUpdate.Status = 4; ApplicationUpdate.UsersDateApproved = DateTime.Now; db.SaveChanges(); } catch (Exception) { return(Json("Error! Unable to update application status details!", JsonRequestBehavior.AllowGet)); } } else { return(Json("Error! Unable to update application status details!", JsonRequestBehavior.AllowGet)); } //1. Send email to Authorized Representative string EmailBody = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/RepresentativeDecline.html"))) { EmailBody = reader.ReadToEnd(); } EmailBody = EmailBody.Replace("{Othernames}", userClientId.Othernames); EmailBody = EmailBody.Replace("{CompanyName}", model.CompanyName); var SendRegistrationCompleteEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, userClientId.Email, "Authorised Representative Decline", EmailBody); if (SendRegistrationCompleteEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody, userClientId.Email, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody, userClientId.Email, _action); } //2. Send confirmation email to client company string EmailBody2 = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ClientConfirmationRepresentativeDecline.html"))) { EmailBody2 = reader.ReadToEnd(); } EmailBody2 = EmailBody2.Replace("{RepresentativeName}", userClientId.Surname + " " + userClientId.Othernames); EmailBody2 = EmailBody2.Replace("{CompanyName}", model.CompanyName); var SendClientConfirmationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, model.CompanyEmail, "Authorised Representative Decline", EmailBody2); if (SendClientConfirmationEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } } return(Json("success", JsonRequestBehavior.AllowGet)); } else { return(Json("Model Invalid! " + errors + " ", JsonRequestBehavior.AllowGet)); } }
// //POST: //AddNewUser public async Task <ActionResult> AddNewUser(PostUsersViewModel model) { if (ModelState.IsValid) { using (DBModel db = new DBModel()) { //Check if Email or Username provided Exists var CheckEmailExists = db.AspNetUsers.Any(i => i.Email == model.Email || i.UserName == model.Email); var _action = "AddNewUser"; if (CheckEmailExists) { //Return error return(Json("User exists! Unable to create new user", JsonRequestBehavior.AllowGet)); } else { //Create User var PasswordResetCode = OTPGenerator.GetUniqueKey(6); string mixedOriginal = Shuffle.StringMixer(PasswordResetCode); var user = new ApplicationUser { UserName = model.Email, Email = model.Email, CompanyName = model.CompanyName, PhoneNumber = model.PhoneNumber, StaffNumber = model.StaffNumber, PasswordResetCode = Functions.GenerateMD5Hash(mixedOriginal), LastPasswordChangedDate = DateTime.Now }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //Add EMT user role UserManager.AddToRole(user.Id, model.UserRole); //Send Success Email to reset password with OTP string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", null, Request.Url.Scheme); var PasswordResetMessageBody = "Dear " + model.CompanyName + ", <br/><br/> You have been created as a user at Global Markets Onboarding Portal." + "<a href=" + callbackUrl + "> Click here to reset your password. </a> Your Reset Code is: " + mixedOriginal + " <br/><br/>" + "Kind Regards,<br/><img src=\"https://e-documents.stanbicbank.co.ke/Content/images/EmailSignature.png\"/>"; var PasswordResetEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, model.Email, "New User: Password Reset", PasswordResetMessageBody); if (PasswordResetEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, PasswordResetMessageBody, model.Email, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, PasswordResetMessageBody, model.Email, _action); } return(Json("success", JsonRequestBehavior.AllowGet)); } else { return(Json("Unable to create new user", JsonRequestBehavior.AllowGet)); } } } } else { return(Json("Invalid form input. Unable to create new user", JsonRequestBehavior.AllowGet)); } }
public JsonResult DeclineNomination(DeclineNominationViewModel model) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { //Upload Signature using (DBModel db = new DBModel()) { //1. Log approval var currentUserId = User.Identity.GetUserId(); var signatoryClientId = db.ClientSignatories.First(c => c.UserAccountID == currentUserId); var LogApproval = db.SignatoryApprovals.Create(); var _action = "DeclineNomination"; LogApproval.ApplicationID = model.ApplicationID; LogApproval.SignatoryID = signatoryClientId.Id; LogApproval.DateApproved = DateTime.Now; LogApproval.Comments = model.Comments; LogApproval.Status = 4; db.SignatoryApprovals.Add(LogApproval); var savedItem = db.SaveChanges(); if (savedItem > 0) { //Log signatory approval var nominationToUpdate = db.ApplicationNominations.SingleOrDefault(c => c.NomineeEmail == signatoryClientId.EmailAddress && c.ApplicationID == model.ApplicationID && c.CompanyID == signatoryClientId.CompanyID && c.NominationType == 1); nominationToUpdate.NominationStatus = 2; db.SaveChanges(); } //2. Update application Id var ApplicationUpdate = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID); var Approvals = ApplicationUpdate.SignatoriesApproved; if (ApplicationUpdate != null) { try { ApplicationUpdate.Status = 4; ApplicationUpdate.SignatoriesDateApproved = DateTime.Now; db.SaveChanges(); } catch (Exception ex) { throw (ex); } } else { return(Json("Unable to Update Application Status Details!", JsonRequestBehavior.AllowGet)); } //3. Send email to signatory string EmailBody = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/SignatoryDecline.html"))) { EmailBody = reader.ReadToEnd(); } EmailBody = EmailBody.Replace("{Othernames}", signatoryClientId.OtherNames); EmailBody = EmailBody.Replace("{CompanyName}", model.CompanyName); var SendRegistrationCompleteEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, signatoryClientId.EmailAddress, "Signatory Decline", EmailBody); if (SendRegistrationCompleteEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody, signatoryClientId.EmailAddress, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody, signatoryClientId.EmailAddress, _action); } //4. Send email to client company string EmailBody2 = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ClientConfirmationSignatoryDecline.html"))) { EmailBody2 = reader.ReadToEnd(); } EmailBody2 = EmailBody2.Replace("{SignatoryName}", signatoryClientId.Surname + " " + signatoryClientId.OtherNames); EmailBody2 = EmailBody2.Replace("{CompanyName}", model.CompanyName); var SendClientConfirmationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, model.CompanyEmail, "Signatory Decline", EmailBody2); if (SendClientConfirmationEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } return(Json("success", JsonRequestBehavior.AllowGet)); } } else { return(Json("Model Invalid! " + errors + " ", JsonRequestBehavior.AllowGet)); } }
//public async Task<ActionResult> Register(RegisterViewModel model) public ActionResult Register(UserAccountModel model) { if (ModelState.IsValid) { using (DBModel db = new DBModel()) { //Check if Email or Account number provided Exists var CheckEmailExists = db.RegisteredClients.Any(i => i.EmailAddress == model.registerModel.EmailAddress.ToLower()); var CheckAccountExists = db.RegisteredClients.Any(i => i.AccountNumber == model.registerModel.StanbicAccountNumber); var CheckUserAccountExists = db.AspNetUsers.Any(i => i.Email == model.registerModel.EmailAddress); var _action = "Register"; //1. Email and Account details exist //Already completed registration process if (CheckEmailExists == true || CheckUserAccountExists == true || CheckAccountExists == true) { ModelState.AddModelError(string.Empty, "Email address or Account number is already registered."); } //2. Email Exists and User account does not exist // For uploaded clients //3. New Users else { //If not Create Client with AccountNumber, Email and Company Name int lastInsertId = db.RegisteredClients.Max(p => p.Id); var activationCode = string.Concat((lastInsertId + 1) + OTPGeneratorReG.GetUniqueKey(6)); string mixedOriginal = Shuffle.StringMixer(activationCode.Substring(2, 6)); //Update RegisteredClient Details try { var newClient = db.RegisteredClients.Create(); newClient.AccountNumber = model.registerModel.StanbicAccountNumber; newClient.EmailAddress = model.registerModel.EmailAddress.ToLower(); newClient.OTP = Functions.GenerateMD5Hash(mixedOriginal); newClient.OTPDateCreated = DateTime.Now; newClient.AcceptedTerms = model.registerModel.terms; newClient.Surname = model.registerModel.Surname; newClient.OtherNames = model.registerModel.Othernames; newClient.AcceptedUserTerms = false; db.RegisteredClients.Add(newClient); var savedClient = db.SaveChanges(); if (savedClient > 0) { //Create New DefaultCompany int lastInsertedClientId = db.RegisteredClients.Max(p => p.Id); var newClientCompany = db.ClientCompanies.Create(); newClientCompany.CompanyName = model.registerModel.CompanyBusinessName; newClientCompany.ClientId = lastInsertedClientId; newClientCompany.Status = 1; newClientCompany.CreatedBy = model.registerModel.EmailAddress; db.ClientCompanies.Add(newClientCompany); var savedClientCompany = db.SaveChanges(); if (savedClientCompany > 0) { //Send Success Email New var callbackUrl = Url.Action("ConfirmRegistration", "Account", null, Request.Url.Scheme); string EmailBody = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ClientRegistrationEmail.html"))) { EmailBody = reader.ReadToEnd(); } EmailBody = EmailBody.Replace("{CompanyName}", model.registerModel.Othernames); EmailBody = EmailBody.Replace("{ActivationCode}", mixedOriginal); EmailBody = EmailBody.Replace("{Url}", callbackUrl); var CompleteRegistrationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, model.registerModel.EmailAddress.ToLower(), "Confirm Registration", EmailBody); if (CompleteRegistrationEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody, model.registerModel.EmailAddress.ToLower(), _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody, model.registerModel.EmailAddress.ToLower(), _action); } //Redirect to Complete Registration/Confirm OTP Page return(RedirectToAction("ConfirmRegistration", "Account")); } else { //Remove Client Details db.RegisteredClients.RemoveRange(db.RegisteredClients.Where(r => r.EmailAddress == model.registerModel.EmailAddress)); db.SaveChanges(); // Send Error to model ModelState.AddModelError(string.Empty, "System Error! Unable to create your default company, please try again later."); } } else { ModelState.AddModelError(string.Empty, "System Error! Unable to create your account, please try again later."); } } catch (Exception) { ModelState.AddModelError(string.Empty, "System Error! Unable to create your account, please try again later."); } } } } // If we got this far, something failed, redisplay form return(View("Index", model)); }
public JsonResult ApproveNomination(ConfirmApproveViewModel model, HttpPostedFileBase inputFile) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { using (DBModel db = new DBModel()) { var currentUserId = User.Identity.GetUserId(); var _userDetails = db.AspNetUsers.SingleOrDefault(e => e.Id == currentUserId); var _action = "ApproveNomination"; var userClientId = db.DesignatedUsers.First(c => c.Email == _userDetails.Email && c.CompanyID == model.CompanyID); //1. Upload Signature if (inputFile != null) { string pic = DateTime.Now.ToString("yyyyMMdd") + currentUserId + System.IO.Path.GetFileName(inputFile.FileName); string path = System.IO.Path.Combine(Server.MapPath("~/Content/images/signatures/"), pic); // Upload file inputFile.SaveAs(path); try { //Save File name to Database //Update Representative Details var DesignatedUserToUpdate = db.DesignatedUsers.FirstOrDefault(c => c.Email == userClientId.Email && c.CompanyID == model.CompanyID); DesignatedUserToUpdate.Signature = pic; DesignatedUserToUpdate.Mobile = model.VerifyPhone; db.SaveChanges(); } catch (Exception) { return(Json("Error! Unable to update representative details", JsonRequestBehavior.AllowGet)); } } else { return(Json("Error! Unable to upload representative signature", JsonRequestBehavior.AllowGet)); } //2. Check if authorized representative is also a signatory var getUserInfo = db.AspNetUsers.SingleOrDefault(c => c.Id == currentUserId); var representativeIsASignatory = db.ClientSignatories.Any(c => c.EmailAddress == getUserInfo.Email && c.CompanyID == model.CompanyID); if (representativeIsASignatory) { var representativeClientId = db.DesignatedUsers.First(c => c.Email == getUserInfo.Email && c.CompanyID == model.CompanyID); //1. Update signatory's signature var SignatoryToUpdate = db.ClientSignatories.First(c => c.EmailAddress == representativeClientId.Email && c.CompanyID == model.CompanyID); SignatoryToUpdate.Signature = representativeClientId.Signature; SignatoryToUpdate.PhoneNumber = model.VerifyPhone; //Update phone number db.SaveChanges(); //2. Log Representative's Approval try { var LogApproval = db.DesignatedUserApprovals.Create(); LogApproval.ApplicationID = model.ApplicationID; LogApproval.UserID = representativeClientId.Id; LogApproval.AcceptedTerms = model.terms; LogApproval.DateApproved = DateTime.Now; db.DesignatedUserApprovals.Add(LogApproval); var savedItem = db.SaveChanges(); if (savedItem > 0) { //Log Representative approval var nominationToUpdate = db.ApplicationNominations.SingleOrDefault(c => c.NomineeEmail == userClientId.Email && c.ApplicationID == model.ApplicationID && c.CompanyID == model.CompanyID && c.NominationType == 2); nominationToUpdate.NominationStatus = 1; db.SaveChanges(); } } catch (Exception) { return(Json("Error! Unable to log representative's details", JsonRequestBehavior.AllowGet)); } //3. Log Signatory Approval try { var signatoryClientId = db.ClientSignatories.First(c => c.EmailAddress == _userDetails.Email && c.CompanyID == model.CompanyID); var LogSigApproval = db.SignatoryApprovals.Create(); LogSigApproval.ApplicationID = model.ApplicationID; LogSigApproval.SignatoryID = signatoryClientId.Id; LogSigApproval.AcceptedTerms = model.terms; LogSigApproval.DateApproved = DateTime.Now; db.SignatoryApprovals.Add(LogSigApproval); var savedItem = db.SaveChanges(); if (savedItem > 0) { //Log nomination var nominationToUpdate = db.ApplicationNominations.SingleOrDefault(c => c.NomineeEmail == userClientId.Email && c.ApplicationID == model.ApplicationID && c.CompanyID == model.CompanyID && c.NominationType == 1); nominationToUpdate.NominationStatus = 1; db.SaveChanges(); } } catch (Exception ex) { return(Json("Error! Unable to log signatory approval" + ex.Message, JsonRequestBehavior.AllowGet)); } //4. Update Application ID var ApplicationUpdate = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID && c.CompanyID == model.CompanyID); if (ApplicationUpdate != null) { try { var SignatoryApprovals = ApplicationUpdate.SignatoriesApproved; var UsersApprovals = ApplicationUpdate.UsersApproved; ApplicationUpdate.SignatoriesApproved = SignatoryApprovals + 1; ApplicationUpdate.UsersApproved = UsersApprovals + 1; ApplicationUpdate.SignatoriesDateApproved = DateTime.Now; ApplicationUpdate.UsersDateApproved = DateTime.Now; db.SaveChanges(); } catch (Exception) { return(Json("Error! Unable to update application details", JsonRequestBehavior.AllowGet)); } } else { return(Json("Unable to update application details!", JsonRequestBehavior.AllowGet)); } //5. Send email to authorized representative string EmailBody = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/RepresentativeApproval.html"))) { EmailBody = reader.ReadToEnd(); } EmailBody = EmailBody.Replace("{Othernames}", userClientId.Othernames); EmailBody = EmailBody.Replace("{CompanyName}", model.CompanyName); var SendRegistrationCompleteEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, userClientId.Email, "Authorised Representative/Signatory Approval", EmailBody); if (SendRegistrationCompleteEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody, userClientId.Email, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody, userClientId.Email, _action); } //6. Send email to company string EmailBody2 = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ClientConfirmationApproval.html"))) { EmailBody2 = reader.ReadToEnd(); } EmailBody2 = EmailBody2.Replace("{Othernames}", model.CompanySurname); EmailBody2 = EmailBody2.Replace("{ApproversName}", userClientId.Surname + " " + userClientId.Othernames); var SendClientConfirmationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, model.CompanyEmail, "Authorised Representative/Signatory Approval", EmailBody2); if (SendClientConfirmationEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } //7. Check if all signatories have approved and send email to representatives if (ApplicationUpdate.SignatoriesApproved >= ApplicationUpdate.Signatories) { //Send Emails to representatives for approval excluding the signatory and sole signatory if in list var _dontSendEmail = db.RegisteredClients.Select(x => x.EmailAddress).ToList(); foreach (var email in db.DesignatedUsers.Where(c => c.ClientID == userClientId.ClientID && c.CompanyID == model.CompanyID && !_dontSendEmail.Contains(c.Email)).ToList()) { var emailExists = db.AspNetUsers.Any(x => x.Email.ToLower() == email.Email.ToLower()); if (!emailExists) { //1. Update Designated User with OTP to Login var _OTPCode = OTPGenerator.GetUniqueKey(6); string OTPCode = Shuffle.StringMixer(_OTPCode); var UserToUpdate = db.DesignatedUsers.SingleOrDefault(c => c.Email == email.Email && c.CompanyID == model.CompanyID); UserToUpdate.OTP = Functions.GenerateMD5Hash(OTPCode); UserToUpdate.DateCreated = DateTime.Now; db.SaveChanges(); //2. Send Email To Representatives var callbackUrl = Url.Action("DesignatedUserConfirmation", "Account", null, Request.Url.Scheme); string EmailBodyRep = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/RepresentativeNomination.html"))) { EmailBodyRep = reader.ReadToEnd(); } EmailBodyRep = EmailBodyRep.Replace("{RepresentativeName}", email.Surname); EmailBodyRep = EmailBodyRep.Replace("{ActivationCode}", OTPCode); EmailBodyRep = EmailBodyRep.Replace("{URL}", callbackUrl); var EmailToRepresentative = MailHelper.SendMailMessage(MailHelper.EmailFrom, email.Email.ToLower(), "Authorized Representative Confirmation", EmailBodyRep); if (EmailToRepresentative == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } } else { //Check if he has already approved var userHasApproved = db.ApplicationNominations.Any(c => c.ApplicationID == model.ApplicationID && c.CompanyID == model.CompanyID && c.NomineeEmail.ToLower() == email.Email.ToLower() && c.NominationType == 2 && c.NominationStatus == 1); if (!userHasApproved) { //1. Send Email To Representatives var callbackUrl = Url.Action("Index", "Home", null, Request.Url.Scheme); string EmailBodyRep = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ExistingRepresentativeNomination.html"))) { EmailBodyRep = reader.ReadToEnd(); } EmailBodyRep = EmailBodyRep.Replace("{RepresentativeName}", email.Surname); EmailBodyRep = EmailBodyRep.Replace("{URL}", callbackUrl); var EmailToRepresentative = MailHelper.SendMailMessage(MailHelper.EmailFrom, email.Email.ToLower(), "Authorized Representative Confirmation", EmailBodyRep); if (EmailToRepresentative == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBodyRep, email.Email.ToLower(), _action); } } } } } //8. Check if all Representatives have approved and send complete email to digital desk var ApplicationToCheck = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID && c.CompanyID == model.CompanyID); if (ApplicationToCheck.UsersApproved == ApplicationToCheck.DesignatedUsers) { //Send Email to Digital Desk and Ops for Approval process var DDUserRole = (from p in db.AspNetUserRoles join e in db.AspNetUsers on p.UserId equals e.Id where (p.RoleId == "03d5e1e3-a8a9-441e-9122-30c3aafccccc" || p.RoleId == "05bdc847-b94d-4d2f-957e-8de1d563106a") && e.Status == 1 select new { EmailID = e.Email }).ToList(); var companyInfo = db.ClientCompanies.SingleOrDefault(c => c.Id == model.CompanyID); foreach (var email in DDUserRole) { var DDMessageBody = "Dear Team <br/><br/> Kindly note that all the signatories and representatives of " + companyInfo.CompanyName + " have approved their nomination. <br/>" + "<br/><br/> Kind Regards, <br /><img src=\"https://e-documents.stanbicbank.co.ke/Content/images/EmailSignature.png\"/>"; var SendDDNotificationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, email.EmailID, "Application Completed", DDMessageBody); if (SendDDNotificationEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, DDMessageBody, email.EmailID, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, DDMessageBody, email.EmailID, _action); } } } } else { //If representative is not a signtory //1. Log Representative's Approval try { var LogApproval = db.DesignatedUserApprovals.Create(); LogApproval.ApplicationID = model.ApplicationID; LogApproval.UserID = userClientId.Id; LogApproval.AcceptedTerms = model.terms; LogApproval.DateApproved = DateTime.Now; db.DesignatedUserApprovals.Add(LogApproval); var savedItem = db.SaveChanges(); if (savedItem > 0) { //Log Representative approval var nominationToUpdate = db.ApplicationNominations.SingleOrDefault(c => c.NomineeEmail == userClientId.Email && c.ApplicationID == model.ApplicationID && c.CompanyID == model.CompanyID && c.NominationType == 2); nominationToUpdate.NominationStatus = 1; db.SaveChanges(); } } catch (Exception) { return(Json("Error! Unable to log representatives details", JsonRequestBehavior.AllowGet)); } //2. Update application ID var ApplicationUpdate = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID && c.CompanyID == model.CompanyID); if (ApplicationUpdate != null) { try { var SignatoryApprovals = ApplicationUpdate.SignatoriesApproved; var UsersApprovals = ApplicationUpdate.UsersApproved; //ApplicationUpdate.SignatoriesApproved = SignatoryApprovals + 1; ApplicationUpdate.UsersApproved = UsersApprovals + 1; ApplicationUpdate.SignatoriesDateApproved = DateTime.Now; ApplicationUpdate.UsersDateApproved = DateTime.Now; db.SaveChanges(); } catch (Exception) { return(Json("Error! Unable to update application details", JsonRequestBehavior.AllowGet)); } } else { return(Json("Unable to update application details!", JsonRequestBehavior.AllowGet)); } //5. Send email to authorized representative string EmailBody = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/RepresentativeApproval.html"))) { EmailBody = reader.ReadToEnd(); } EmailBody = EmailBody.Replace("{Othernames}", userClientId.Othernames); EmailBody = EmailBody.Replace("{CompanyName}", model.CompanyName); var SendRegistrationCompleteEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, userClientId.Email, "Authorised Representative Approval", EmailBody); if (SendRegistrationCompleteEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody, userClientId.Email, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody, userClientId.Email, _action); } //6. Send email to company string EmailBody2 = string.Empty; using (System.IO.StreamReader reader = new StreamReader(Server.MapPath("~/Content/emails/ClientConfirmationApproval.html"))) { EmailBody2 = reader.ReadToEnd(); } EmailBody2 = EmailBody2.Replace("{Othernames}", model.CompanySurname); EmailBody2 = EmailBody2.Replace("{ApproversName}", userClientId.Surname + " " + userClientId.Othernames); var SendClientConfirmationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, model.CompanyEmail, "Authorised Representative Approval", EmailBody2); if (SendClientConfirmationEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, EmailBody2, model.CompanyEmail, _action); } //7. Check if all Representatives have approved and send complete email to digital desk and ops var ApplicationToCheck = db.EMarketApplications.SingleOrDefault(c => c.Id == model.ApplicationID && c.CompanyID == model.CompanyID); if (ApplicationToCheck.UsersApproved == ApplicationToCheck.DesignatedUsers) { //Send Email to Digital Desk and Ops for Approval process var DDUserRole = (from p in db.AspNetUserRoles join e in db.AspNetUsers on p.UserId equals e.Id where (p.RoleId == "03d5e1e3-a8a9-441e-9122-30c3aafccccc" || p.RoleId == "05bdc847-b94d-4d2f-957e-8de1d563106a") && e.Status == 1 select new { EmailID = e.Email }).ToList(); var companyInfo = db.ClientCompanies.SingleOrDefault(c => c.Id == model.CompanyID); foreach (var email in DDUserRole) { var DDMessageBody = "Dear Team <br/><br/> Kindly note that all the signatories and representatives of " + companyInfo.CompanyName + " have approved their nomination. <br/>" + "<br/><br/> Kind Regards, <br /><img src=\"https://e-documents.stanbicbank.co.ke/Content/images/EmailSignature.png\"/>"; var SendDDNotificationEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, email.EmailID, "Application Completed", DDMessageBody); if (SendDDNotificationEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, DDMessageBody, email.EmailID, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, DDMessageBody, email.EmailID, _action); } } } } } return(Json("success", JsonRequestBehavior.AllowGet)); } else { return(Json("Model Invalid! " + errors + " ", JsonRequestBehavior.AllowGet)); } }