protected void DoExport(object objConfiguration) { try { var conf = objConfiguration as ExportConfiguration; HccRequestContext.Current = conf.HccRequestContext; DnnGlobal.SetPortalSettings(conf.DnnPortalSettings); Factory.HttpContext = conf.HttpContext; CultureSwitch.SetCulture(HccApp.CurrentStore, conf.DnnPortalSettings); var products = HccApp.CatalogServices.Products.FindByCriteria(conf.Criteria, 1, int.MaxValue, ref RowCount, false); var export = new CatalogExport(HccApp); var fileName = string.Format("Hotcakes_Products_{0}_{1:yyyyMMddhhMMss}.xlsx", HccApp.CurrentCustomerId, DateTime.UtcNow); var filePath = DiskStorage.GetStoreDataPhysicalPath(HccApp.CurrentStore.Id, "Exports/" + fileName); export.ExportToExcel(products, filePath); var pageLink = DiskStorage.GetHccAdminUrl(HccApp, "catalog/default.aspx", false); var mailMessage = new MailMessage(conf.DnnPortalSettings.Email, HccApp.CurrentCustomer.Email); mailMessage.IsBodyHtml = true; mailMessage.Body = Localization.GetFormattedString("ExportProductsMailBody", pageLink); mailMessage.Subject = Localization.GetString("ExportProductsMailSubject"); MailServices.SendMail(mailMessage, HccApp.CurrentStore); } catch (Exception ex) { EventLog.LogEvent(ex); } }
protected void EmailPasswordToCustomer(OrderTaskContext context, CustomerAccount n) { try { var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(context.RequestContext, context.Order.UsedCulture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var t = context.HccApp.ContentServices.GetHtmlTemplateOrDefault(HtmlTemplateType.ForgotPassword); if (t != null) { var replacers = new List <IReplaceable>(); replacers.Add(n); replacers.Add(new Replaceable("[[NewPassword]]", n.Password)); t = t.ReplaceTagsInTemplate(hccRequestContext, replacers); var m = t.ConvertToMailMessage(n.Email); if (!MailServices.SendMail(m, hccRequestContext.CurrentStore)) { EventLog.LogEvent("Create Account During Checkout", "Failed to send email to new customer " + n.Email, EventLogSeverity.Warning); } } } catch (Exception ex) { EventLog.LogEvent(ex); } }
public override bool Execute(OrderTaskContext context) { var u = context.HccApp.MembershipServices.Customers.FindByEmail(context.Order.UserEmail).FirstOrDefault(); if (u != null) { if (u.Bvin != string.Empty) { context.UserId = u.Bvin; return(true); } } var n = new CustomerAccount(); n.Email = context.Order.UserEmail; var length = WebAppSettings.PasswordMinimumLength; if (length < 8) { length = 8; } var newPassword = PasswordGenerator.GeneratePassword(length); n.Password = newPassword; n.FirstName = context.Order.ShippingAddress.FirstName; n.LastName = context.Order.ShippingAddress.LastName; if (context.HccApp.MembershipServices.CreateCustomer(n, n.Password)) { // Update Addresses for Customer context.Order.BillingAddress.CopyTo(n.BillingAddress); context.Order.ShippingAddress.CopyTo(n.ShippingAddress); context.HccApp.MembershipServices.UpdateCustomer(n); context.Order.CustomProperties.Add("hcc", "allowpasswordreset", "1"); // Email Password to Customer var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(context.RequestContext, context.Order.UsedCulture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var t = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.ForgotPassword); if (t != null) { var replacers = new List <IReplaceable>(); replacers.Add(n); replacers.Add(new Replaceable("[[NewPassword]]", newPassword)); t = t.ReplaceTagsInTemplate(hccRequestContext, replacers); var m = t.ConvertToMailMessage(n.Email); if (!MailServices.SendMail(m, hccRequestContext.CurrentStore)) { EventLog.LogEvent("Create Account During Checkout", "Failed to send email to new customer " + n.Email, EventLogSeverity.Warning); } } } context.UserId = n.Bvin; return(true); }
private bool SendEmail(OrderTaskContext context, VendorManufacturer vendorOrManufacturer, Order order) { var storeSettingsProvider = Factory.CreateStoreSettingsProvider(); var defaultCulture = storeSettingsProvider.GetDefaultLocale(); var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(context.RequestContext, defaultCulture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var toEmail = vendorOrManufacturer.EmailAddress; HtmlTemplate t = null; var templateBvin = vendorOrManufacturer.DropShipEmailTemplateId; if (templateBvin != string.Empty) { long templateId = 0; long.TryParse(templateBvin, out templateId); t = contentService.HtmlTemplates.Find(templateId); } if (t == null) { t = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.DropShippingNotice); } if (!string.IsNullOrEmpty(toEmail)) { var replacers = new List <IReplaceable>(); replacers.Add(order); replacers.Add(vendorOrManufacturer); t = t.ReplaceTagsInTemplate(hccRequestContext, replacers, order.ItemsAsReplaceable()); var m = t.ConvertToMailMessage(toEmail); return(MailServices.SendMail(m, hccRequestContext.CurrentStore)); } return(false); }
public void Execute(HotcakesApplication hccApp, Order order) { try { var toEmail = hccApp.CurrentStore.Settings.MailServer.EmailForGeneral; if (!string.IsNullOrEmpty(toEmail)) { var storeSettingsProvider = Factory.CreateStoreSettingsProvider(); var defaultCulture = storeSettingsProvider.GetDefaultLocale(); var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(hccApp.CurrentRequestContext, defaultCulture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var t = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.FreeProductIsOutOfStock); t = t.ReplaceTagsInTemplate(hccRequestContext, order, order.ItemsAsReplaceable()); var m = t.ConvertToMailMessage(toEmail); MailServices.SendMail(m, hccRequestContext.CurrentStore); } } catch (Exception ex) { EventLog.LogEvent(ex); } }
public override bool Execute(OrderTaskContext context) { try { if (context.Order.ApplyVATRules && !context.Order.IsRecurring) { var toEmail = context.HccApp.CurrentStore.Settings.MailServer.EmailForGeneral; if (!string.IsNullOrEmpty(toEmail)) { var storeSettingsProvider = Factory.CreateStoreSettingsProvider(); var defaultCulture = storeSettingsProvider.GetDefaultLocale(); var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(context.RequestContext, defaultCulture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var t = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.FreeProductIsOutOfStock); t = t.ReplaceTagsInTemplate(hccRequestContext, context.Order, context.Order.ItemsAsReplaceable()); var m = t.ConvertToMailMessage(toEmail); MailServices.SendMail(m, hccRequestContext.CurrentStore); } } } catch (Exception ex) { EventLog.LogEvent(ex); } return(true); }
public RequestResult <object> Help(string Email, string Message, string UserEmail = null) { try { SystemVariableServices SV = new SystemVariableServices(); var Key = Crypto.ToBase64(SV.GetSystemVariableValue("CryptoKey")).ToString().Substring(0, 16); var Iv = Crypto.ToBase64(SV.GetSystemVariableValue("CryptoIV")).ToString().Substring(0, 16); var _Email = (!string.IsNullOrEmpty(UserEmail)) ? UserEmail : Crypto.DecryptString(Email, Key, Iv); var _Message = Crypto.DecryptString(Message, Key, Iv); var _To = SV.GetSystemVariableValue("SupportEmailInbox"); var _From = SV.GetSystemVariableValue("EgulfSupportEmail"); MailServices MailServ = new MailServices(); ITemplate factory = new TemplateMessagesFactory(); Dictionary <string, string[]> param = new Dictionary <string, string[]>(); param.Add("{Enfasis}", new string[] { _Message }); param.Add("{Text}", new string[] { _Email }); MailServ.SendMail(factory.GetTemplate(_To, "NewIncident", param, _From)); return(new RequestResult <object> { Status = Status.Success }); } catch (Exception ex) { return(new RequestResult <object> { Status = Status.Error }); } }
public override bool Execute(OrderTaskContext context) { try { if (context.Order.ApplyVATRules && !context.Order.IsRecurring) { var toEmail = context.Order.UserEmail; if (!string.IsNullOrEmpty(toEmail)) { var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(context.RequestContext, context.Order.UsedCulture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var t = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.VATInvoice); t = t.ReplaceTagsInTemplate(hccRequestContext, context.Order, context.Order.ItemsAsReplaceable()); var m = t.ConvertToMailMessage(toEmail); MailServices.SendMail(m, hccRequestContext.CurrentStore); } } } catch (Exception ex) { EventLog.LogEvent(ex); } return(true); }
private void SendAbandonedCartEmail(HccRequestContext context, Order order) { try { var membershipServices = Factory.CreateService <MembershipServices>(context); var customer = membershipServices.Customers.Find(order.UserID); if (customer != null && !string.IsNullOrEmpty(customer.Email)) { var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(context, order.UsedCulture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var template = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.AbandonedCart); template = template.ReplaceTagsInTemplate(hccRequestContext, order, order.ItemsAsReplaceable()); var mailMessage = template.ConvertToMailMessage(customer.Email); MailServices.SendMail(mailMessage, hccRequestContext.CurrentStore); order.IsAbandonedEmailSent = true; var orderService = Factory.CreateService <OrderService>(hccRequestContext); orderService.Orders.Update(order); } } catch (Exception ex) { EventLog.LogEvent(ex); } }
public override bool Execute(OrderTaskContext context) { CustomerAccount u = context.MTApp.MembershipServices.Customers.FindByEmail(context.Order.UserEmail); if (u != null) { if (u.Bvin != string.Empty) { return(true); } } CustomerAccount n = new CustomerAccount(); n.Email = context.Order.UserEmail; int length = WebAppSettings.PasswordMinimumLength; if (length < 8) { length = 8; } string newPassword = MerchantTribe.Web.PasswordGenerator.GeneratePassword(length); n.Password = newPassword; n.FirstName = context.Order.ShippingAddress.FirstName; n.LastName = context.Order.ShippingAddress.LastName; if (context.MTApp.MembershipServices.CreateCustomer(n, n.Password)) { // Update Addresses for Customer context.Order.BillingAddress.CopyTo(n.BillingAddress); context.Order.ShippingAddress.CopyTo(n.ShippingAddress); context.MTApp.MembershipServices.UpdateCustomer(n); context.Order.CustomProperties.Add("bvsoftware", "allowpasswordreset", "1"); // Email Password to Customer HtmlTemplate t = context.MTApp.ContentServices.GetHtmlTemplateOrDefault(HtmlTemplateType.ForgotPassword); if (t != null) { System.Net.Mail.MailMessage m; List <IReplaceable> replacers = new List <IReplaceable>(); replacers.Add(n); replacers.Add(new Replaceable("[[NewPassword]]", newPassword)); t = t.ReplaceTagsInTemplate(context.MTApp, replacers); m = t.ConvertToMailMessage(n.Email); if (MailServices.SendMail(m, context.MTApp.CurrentStore) == false) { EventLog.LogEvent("Create Account During Checkout", "Failed to send email to new customer " + n.Email, EventLogSeverity.Warning); } } } context.UserId = n.Bvin; return(true); }
/// <summary> /// Use this method to send an email to the merchant about the low stock level. /// </summary> /// <param name="recipientEmail">String - the email address where to send the low stock report to</param> /// <param name="storeName">String - the name of the store to use for the email template</param> /// <param name="app">An active instance of HotcakesApplication, used to access store settings.</param> /// <returns>If true, the email was sent successfully using the given parameters.</returns> public static bool EmailLowStockReport(string recipientEmail, string storeName, HotcakesApplication app) { var result = false; try { var fromAddress = string.Empty; fromAddress = recipientEmail; var m = new MailMessage(fromAddress, recipientEmail); m.IsBodyHtml = false; m.Subject = "Low Stock Report From " + storeName; var sb = new StringBuilder(); sb.AppendLine("The following are low in stock or out of stock:"); sb.Append(Environment.NewLine); var inventories = app.CatalogServices.ProductInventories.FindAllLowStock(); if (inventories.Count < 1) { sb.Append("No out of stock items found."); } else { foreach (var item in inventories) { var product = app.CatalogServices.Products.Find(item.ProductBvin); if (product != null) { sb.Append(WebAppSettings.InventoryLowReportLinePrefix); sb.Append(product.Sku); sb.Append(", "); sb.Append(product.ProductName); sb.Append(", "); sb.Append(item.QuantityOnHand); sb.AppendLine(" "); } } } m.Body = sb.ToString(); result = MailServices.SendMail(m, app.CurrentStore); } catch (Exception ex) { EventLog.LogEvent(ex); result = false; } return(result); }
public override bool Execute(OrderTaskContext context) { string toEmail = null; HtmlTemplate template = null; var culture = "en-US"; switch (_emailTo) { case "Admin": toEmail = context.HccApp.CurrentStore.Settings.MailServer.EmailForNewOrder; var storeSettingsProvider = Factory.CreateStoreSettingsProvider(); culture = storeSettingsProvider.GetDefaultLocale(); break; case "Customer": toEmail = context.Order.UserEmail; culture = context.Order.UsedCulture; break; } var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(context.RequestContext, culture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); switch (_emailTo) { case "Admin": template = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.NewOrderForAdmin); break; case "Customer": template = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.NewOrder); break; } try { if (!string.IsNullOrEmpty(toEmail)) { template = template.ReplaceTagsInTemplateForOrder(hccRequestContext, context.Order); var m = template.ConvertToMailMessage(toEmail); MailServices.SendMail(m, hccRequestContext.CurrentStore); } } catch (Exception ex) { EventLog.LogEvent(ex); } return(true); }
private void SendMailInvitation(string email) { MailServices MailServ = new MailServices(); ITemplate factory = new TemplateMessagesFactory(); CompanyServices csrv = new CompanyServices(); var company = csrv.Get(new CompanyModel() { CompanyId = UserCompanyId }).FirstOrDefault(); Dictionary <string, string[]> parsm = new Dictionary <string, string[]>(); parsm.Add("{Enfasis}", new string[] { company.CompanyName }); MailServ.SendMail(factory.GetTemplate(email, "InvitationCompany", parsm)); }
public void SendAffiliateReviewEmail(Affiliate aff) { var storeSettingsProvider = Factory.CreateStoreSettingsProvider(); var defaultCulture = storeSettingsProvider.GetDefaultLocale(); var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(Context, defaultCulture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var template = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.AffiliateReview); template = template.ReplaceTagsInTemplate(hccRequestContext, aff); var storeAdmin = hccRequestContext.CurrentStore.Settings.MailServer.EmailForNewOrder; var message = template.ConvertToMailMessage(storeAdmin); MailServices.SendMail(message, hccRequestContext.CurrentStore); }
private void SendMails(RSVP rsvp) { try { MailServices mailSvc = new MailServices(); string mailGuest = mailSvc.PrepareRSVPMailToGuest(rsvp); string mailAdmin = mailSvc.PrepareRSVPMailToAdmins(rsvp); mailSvc.SendMail("Il tuo RSVP", mailGuest, new List <string>() { rsvp.Email }); mailSvc.SendMail("Nuovo RSVP", mailAdmin, new List <string>() { "*****@*****.**" }); } catch (Exception exc) { exc.WriteToLog(); } }
public void SendGiftCardNotification(GiftCard giftCard, Order order, LineItem item) { var usedCulture = order != null ? order.UsedCulture : "en-US"; var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(Context, usedCulture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var template = GetHtmlTemplateOrDefault(HtmlTemplateType.GiftCardNotification); template = template.ReplaceTagsInTemplate(hccRequestContext, new List <IReplaceable> { item, giftCard }); var message = template.ConvertToMailMessage(giftCard.RecipientEmail); MailServices.SendMail(message, hccRequestContext.CurrentStore); }
protected void btnSendStatusEmail_Click(object sender, EventArgs e) { long templateId = 0; long.TryParse(lstEmailTemplate.SelectedValue, out templateId); var t = HccApp.ContentServices.HtmlTemplates.Find(templateId); if (t == null) { return; } var toEmail = CurrentOrder.UserEmail; var culture = CurrentOrder.UsedCulture; if (t.TemplateType == HtmlTemplateType.NewOrderForAdmin || t.TemplateType == HtmlTemplateType.DropShippingNotice || t.TemplateType == HtmlTemplateType.ContactFormToAdmin) { toEmail = HccApp.CurrentStore.Settings.MailServer.EmailForNewOrder; var storeSettingsProvider = Factory.CreateStoreSettingsProvider(); culture = storeSettingsProvider.GetDefaultLocale(); } var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(HccRequestContext.Current, culture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); if (!string.IsNullOrWhiteSpace(toEmail)) { // this time get template in correct culture t = contentService.HtmlTemplates.Find(templateId); t = t.ReplaceTagsInTemplateForOrder(hccRequestContext, CurrentOrder); var m = t.ConvertToMailMessage(toEmail); if (MailServices.SendMail(m, hccRequestContext.CurrentStore)) { ucMessageBox.ShowOk("E-Mail Sent!"); } else { ucMessageBox.ShowError("Message Send Failed."); } } LoadOrder(); }
public void SendAffiliateApprovementEmail(Affiliate aff, string culture = "") { var storeSettingsProvider = Factory.CreateStoreSettingsProvider(); if (string.IsNullOrEmpty(culture)) { culture = storeSettingsProvider.GetDefaultLocale(); } var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(Context, culture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var template = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.AffiliateApprovement); template = template.ReplaceTagsInTemplate(hccRequestContext, aff); var message = template.ConvertToMailMessage(aff.Email); MailServices.SendMail(message, hccRequestContext.CurrentStore); }
public override bool Execute(OrderTaskContext context) { var EmailSelection = string.Empty; EmailSelection = _ToEmail; var toEmail = string.Empty; switch (EmailSelection) { case "Admin": toEmail = context.HccApp.CurrentRequestContext.CurrentStore.Settings.MailServer.EmailForNewOrder; break; case "Customer": toEmail = context.Order.UserEmail; break; default: toEmail = context.Order.UserEmail; EmailSelection = "Customer"; break; } try { if (toEmail.Trim().Length > 0) { var storeSettingsProvider = Factory.CreateStoreSettingsProvider(); var defaultCulture = context.Order.UsedCulture; var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(context.RequestContext, defaultCulture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var t = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.OrderShipment); t = t.ReplaceTagsInTemplateForOrder(hccRequestContext, context.Order); var m = t.ConvertToMailMessage(toEmail); MailServices.SendMail(m, hccRequestContext.CurrentStore); } } catch (Exception ex) { EventLog.LogEvent(ex); } return(true); }
private void SendEmails(List <CustomerAccount> users, HccRequestContext hccContext) { HccRequestContext.Current = hccContext; var contentService = Factory.CreateService <ContentService>(hccContext); var template = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.ContactAbandonedCartUsers); var customMessage = txtCustomMessage.Text.Trim(); var customMessageTag = new Replaceable("[[CustomMessage]]", customMessage); template = template.ReplaceTagsInTemplate(hccContext, customMessageTag); foreach (var user in users) { if (user != null && !string.IsNullOrEmpty(user.Email)) { var mailMessage = template.ConvertToMailMessage(user.Email); MailServices.SendMail(mailMessage, hccContext.CurrentStore); } } }
public void SendNewRolesAssignment(CustomerAccount acc, string[] roles) { var roleTags = new Replaceable("[[User.NewRoles]]", string.Join(", ", roles)); var storeSettingsProvider = Factory.CreateStoreSettingsProvider(); var defaultCulture = storeSettingsProvider.GetDefaultLocale(); var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(Context, defaultCulture); var contentService = Factory.CreateService <ContentService>(hccRequestContext); var template = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.NewRoleAssignment); template = template.ReplaceTagsInTemplate(hccRequestContext, new List <IReplaceable> { acc, roleTags }); var message = template.ConvertToMailMessage(acc.Email); MailServices.SendMail(message, hccRequestContext.CurrentStore); }
// Mailing List Send Functions public void SendToList(HtmlTemplate t, bool sendAsync, HotcakesApplication app) { if (t == null) { return; } foreach (var m in Members) { try { var copy = t.ReplaceTagsInTemplate(app.CurrentRequestContext, m); var msg = copy.ConvertToMailMessage(m.EmailAddress); MailServices.SendMail(msg, app.CurrentStore); } catch (Exception ex) { EventLog.LogEvent(ex); } } }
protected void btnSendTest_Click(object sender, ImageClickEventArgs e) { SaveData(); msg.ClearMessage(); var m = new MailMessage("*****@*****.**", TestToField.Text.Trim()) { Subject = "Mail Server Test Message", Body = "Your mail server appears to be correctly configured!", IsBodyHtml = false }; if (MailServices.SendMail(m, HccApp.CurrentStore)) { msg.ShowOk("Test Message Sent"); } else { msg.ShowError("Test Failed. Please check your settings and try again."); } m = null; }
/// <summary> /// Offer from Project to Vessel /// Validations /// Insert offer with Status NEW /// Send alert to Vessel company owners /// Send mail to Vessel company owners /// </summary> /// <param name="offer"></param> /// <returns></returns> public RequestResult <List <AlertModel> > InsComplete(OfferModel offer) { RequestResult <List <AlertModel> > resp = new RequestResult <List <AlertModel> >() { Status = Status.Success }; OfferDA offerDA = new OfferDA(); VesselServices vesselServices = new VesselServices(); PersonServices personServices = new PersonServices(); AlertServices alertServices = new AlertServices(); List <AlertModel> lstAlertToSend = new List <AlertModel>(); MailServices MailServ = new MailServices(); ITemplate factory = new TemplateMessagesFactory(); TransactionOptions scopeOptions = new TransactionOptions(); ////scopeOptions.IsolationLevel = IsolationLevel.ReadCommitted; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, scopeOptions)) { try { if (offer.Vessel.VesselId == null) { throw new Exception("VesselId REQUIRED"); } if (offer.Project.ProjectId == null) { throw new Exception("ProjectId REQUIRED"); } if (offer.ProjectAdmin.PersonId == null) { throw new Exception("ProjectAdmin.PersonId REQUIRED"); } OfferModel val = new OfferModel(); List <OfferModel> lstVal = new List <OfferModel>(); val.Project.ProjectId = offer.Project.ProjectId; val.Vessel.VesselId = offer.Vessel.VesselId; lstVal = Get(val); if (lstVal.Count > 0) { throw new Exception("STATUS_NOT_VALID"); } VesselModel vessel = new VesselModel(); vessel.VesselId = offer.Vessel.VesselId; vessel = vesselServices.Get(vessel).FirstOrDefault(); // Insert offer with Status NEW var respOffer = offerDA.InsUpd(offer); if (respOffer.Status != Status.Success) { throw new Exception(respOffer.Message); } // Send alert to Vessel company owners //Listado de los usuarios de una compañía UserPersonModel person = new UserPersonModel(); person.CompanyId = vessel.Company.CompanyId; List <UserPersonModel> lst = personServices.getUserPerson(person); Dictionary <string, string> values = new Dictionary <string, string>(); values.Add("IMO", vessel.Imo); values.Add("VESSELNAME", vessel.Name); AlertModel alert = alertServices.GetWithValues(6, values); SystemVariableServices SVS = new SystemVariableServices(); Dictionary <string, string[]> param = new Dictionary <string, string[]>(); string EgulfUrl = SVS.GetSystemVariableValue("EgulfWeb"); param.Add("{Enfasis}", new string[] { vessel.Imo, vessel.Name }); param.Add("{Btn_url}", new string[] { EgulfUrl }); foreach (UserPersonModel personItem in lst) { AlertModel alertAux = alert.Clone(); alertAux.To = personItem.PersonId; lstAlertToSend.Add(alertAux); MailServ.SendMail(factory.GetTemplate(personItem.Email, "VesselOfferReceived", param)); } var respAlert = alertServices.InsUpd(lstAlertToSend); if (respAlert != null) { throw new Exception(respAlert.Message); } resp.Data = lstAlertToSend; ts.Complete(); } catch (Exception ex) { ts.Dispose(); resp = new RequestResult <List <AlertModel> >() { Status = Status.Error, Message = ex.Message }; Elmah.ErrorSignal.FromCurrentContext().Raise(ex); throw ex; } } return(resp); }
public RequestResult <List <AlertModel> > Fix(OfferModel model) { RequestResult <List <AlertModel> > resp = new RequestResult <List <AlertModel> >(); MailServices MailServ = new MailServices(); ITemplate factory = new TemplateMessagesFactory(); VesselServices vesselServices = new VesselServices(); AlertServices alertServices = new AlertServices(); AlertTemplateServices templateServices = new AlertTemplateServices(); List <AlertModel> lstAlertToSend = new List <AlertModel>(); if (model.OfferId == null) { throw new Exception("REQUIRED OfferId"); } TransactionOptions scopeOptions = new TransactionOptions(); ////scopeOptions.IsolationLevel = IsolationLevel.ReadCommitted; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, scopeOptions)) { try { OfferModel val = GetById((int)model.OfferId); if (val == null) { throw new Exception("NOT_FOUND"); } if (val.Status != OfferModel.NEW) { throw new Exception("STATUS_NOT_VALID"); } OfferModel modelUpd = new OfferModel(); modelUpd.OfferId = model.OfferId; model.Status = OfferModel.FIX; InsUpd(model); Dictionary <string, string> values = new Dictionary <string, string>(); values.Add("FLAG", val.Vessel.Country.Name); values.Add("HOMEPORT", val.Vessel.HomePort.Name); values.Add("IMO", val.Vessel.Imo); values.Add("VESSELNAME", val.Vessel.Name); values.Add("FOLIO", val.Project.Folio); //Notify to project owner alert and mail AlertModel alertFix = alertServices.GetWithValues(7, values); alertFix.To = val.ProjectAdmin.PersonId; lstAlertToSend.Add(alertFix); var respAlert = alertServices.InsUpd(alertFix); if (respAlert != null) { throw new Exception(respAlert.Message); } SystemVariableServices SVS = new SystemVariableServices(); Dictionary <string, string[]> param = new Dictionary <string, string[]>(); string EgulfUrl = SVS.GetSystemVariableValue("EgulfWeb"); param.Add("{Enfasis}", new string[] { val.Vessel.Country.Name, val.Vessel.HomePort.Name, val.Project.Folio }); param.Add("{Btn_url}", new string[] { EgulfUrl }); MailServ.SendMail(factory.GetTemplate(val.ProjectAdmin.Email, "OfferFix", param)); resp.Data = lstAlertToSend; ts.Complete(); } catch (Exception ex) { ts.Dispose(); resp = new RequestResult <List <AlertModel> >() { Status = Status.Error, Message = ex.Message }; Elmah.ErrorSignal.FromCurrentContext().Raise(ex); throw ex; } } return(resp); }
public RequestResult <object> SingUp(PersonModel personParameters, User userParameters) { TransactionOptions scopeOptions = new TransactionOptions(); //scopeOptions.IsolationLevel = IsolationLevel.ReadCommitted; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, scopeOptions)) { try { UserServices UserServ = new UserServices(); User responseValidateUser = UserServ.valExistingUsername(userParameters); if (responseValidateUser.UserId > 0) { return(new RequestResult <object> { Status = Status.Warning, Message = "MsgUserExisting" }); } else { userParameters.UserId = 0; User responseInsUpdUser = UserServ.insUpdUser(userParameters); if (responseInsUpdUser.UserId > 0) { RequestResult <PersonModel> personIdEmailExisting = valExistingEmail(personParameters); if (personIdEmailExisting.Data.PersonId > 0) { return(new RequestResult <object> { Status = Status.Warning, Message = "MsgEmailExisting" }); } else { personParameters.UserId = responseInsUpdUser.UserId; RequestResult <object> personResponse = insUpdPerson(personParameters); if (personResponse.Status == Status.Error) { throw new Exception("An unespected error was detected on create person"); } MailServices MailServ = new MailServices(); ITemplate factory = new TemplateMessagesFactory(); SystemVariableServices SVS = new SystemVariableServices(); Dictionary <string, string[]> param = new Dictionary <string, string[]>(); string EgulfUrl = SVS.GetSystemVariableValue("EgulfWeb"); param.Add("{Btn_url}", new string[] { EgulfUrl }); MailServ.SendMail(factory.GetTemplate(personParameters.Email, "WelcomeT", param)); //MailServ.wellcomeEmail(personParameters.Email); ts.Complete(); return(personResponse); } } else { throw new Exception("An unespected error was detected on create user"); } } } catch (Exception ex) { ts.Dispose(); return(new RequestResult <object>() { Status = Status.Error, Message = ex.Message }); } } }
public RequestResult <object> RecoverAccount(string SecureEmail) { TransactionOptions scopeOptions = new TransactionOptions(); //scopeOptions.IsolationLevel = IsolationLevel.ReadCommitted; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, scopeOptions)) { try { SystemVariableServices SV = new SystemVariableServices(); var Key = Crypto.ToBase64(SV.GetSystemVariableValue("CryptoKey")).ToString().Substring(0, 16); var Iv = Crypto.ToBase64(SV.GetSystemVariableValue("CryptoIV")).ToString().Substring(0, 16); var Email = Crypto.DecryptString(SecureEmail, Key, Iv); RequestResult <PersonModel> ValidAccount = valExistingEmail(new PersonModel() { Email = Email }); if (ValidAccount.Data.PersonId > 0) { PersonModel PersonData = GetPerson((int)ValidAccount.Data.PersonId); const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; Random randomChar = new Random(); var NewPassword = new string(Enumerable.Repeat(chars, 10).Select(s => s[randomChar.Next(s.Length)]).ToArray()); var NewSecurePassword = Crypto.EncryptString(NewPassword, Key, Iv); UserServices UserServ = new UserServices(); User userData = UserServ.SelUser(new User() { UserId = PersonData.UserId }); userData.Password = NewSecurePassword; User responseInsUpdUser = UserServ.insUpdUser(userData); if (responseInsUpdUser.UserId > 0) { MailServices MailServ = new MailServices(); ITemplate factory = new TemplateMessagesFactory(); SystemVariableServices SVS = new SystemVariableServices(); Dictionary <string, string[]> param = new Dictionary <string, string[]>(); string EgulfUrl = SVS.GetSystemVariableValue("EgulfWeb"); param.Add("{Btn_url}", new string[] { EgulfUrl }); param.Add("{Text}", new string[] { userData.UserName, NewPassword }); MailServ.SendMail(factory.GetTemplate(Email, "ResetAccount", param)); ts.Complete(); return(new RequestResult <object> { Status = Status.Success }); } else { throw new Exception("An unexpected error occurred at restore account process"); } } else { return(new RequestResult <object> { Status = Status.Warning }); } } catch (Exception ex) { ts.Dispose(); return(new RequestResult <object> { Status = Status.Error, Message = ex.Message }); } } }
private void SendReminder(string email) { if (!MerchantTribe.Web.Validation.EmailValidation.MeetsEmailFormatRequirements(email)) { FlashWarning("Please enter a valid email address"); return; } try { CustomerAccount thisUser = MTApp.MembershipServices.Customers.FindByEmail(email); string newPassword = string.Empty; if ((thisUser != null) && (thisUser.Bvin != string.Empty)) { newPassword = MTApp.MembershipServices.GeneratePasswordForCustomer(WebAppSettings.PasswordMinimumLength + 2); thisUser.Password = thisUser.EncryptPassword(newPassword); if (MTApp.MembershipServices.UpdateCustomer(thisUser)) { HtmlTemplate t = MTApp.ContentServices.GetHtmlTemplateOrDefault(HtmlTemplateType.ForgotPassword); if (t != null) { System.Net.Mail.MailMessage m; List <IReplaceable> tempList = new List <IReplaceable>(); tempList.Add(thisUser); tempList.Add(new Replaceable("[[NewPassword]]", newPassword)); t = t.ReplaceTagsInTemplate(MTApp, tempList); m = t.ConvertToMailMessage(thisUser.Email); if (MailServices.SendMail(m) == false) { FlashFailure("Error while sending mail!"); } } FlashSuccess("Your new password has been sent by email."); } else { FlashFailure("An error occurred while trying to update password."); } } else { FlashFailure(SiteTerms.GetTerm(SiteTermIds.Username) + " not found."); } } catch (SystemMembershipUserException CreateEx) { switch (CreateEx.Status) { case CreateUserStatus.UpdateFailed: FlashFailure("Update to user account failed."); break; default: FlashFailure(CreateEx.Message); break; } } }