public virtual IActionResult SubscribeNewsletter(string email, bool subscribe) { string result; var success = false; if (!CommonHelper.IsValidEmail(email)) { result = _localizationService.GetResource("Newsletter.Email.Wrong"); } else { email = email.Trim(); var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(email, _storeContext.CurrentStore.Id); if (subscription != null) { if (subscribe) { if (!subscription.Active) { _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); } result = _localizationService.GetResource("Newsletter.SubscribeEmailSent"); } else { if (subscription.Active) { _workflowMessageService.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id); } result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent"); } } else if (subscribe) { subscription = new NewsLetterSubscription { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = email, Active = false, StoreId = _storeContext.CurrentStore.Id, CreatedOnUtc = DateTime.UtcNow }; _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); result = _localizationService.GetResource("Newsletter.SubscribeEmailSent"); } else { result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent"); } success = true; } return(Json(new { Success = success, Result = result, })); }
public HttpResponseMessage Register(RegisterModel model) { var response = this.Request.CreateResponse(HttpStatusCode.OK); try { string jsonString = ""; var Sponsors = _customerService.GetCustomerByUsername(model.SponsorsName); //check whether registration is allowed if (_customerSettings.UserRegistrationType == UserRegistrationType.Disabled) { //Registrition Disable //(int)UserRegistrationType.Disabled } var customer = _customerService.InsertGuestCustomer(); if (customer.Id != 0) { _workContext.CurrentCustomer = customer; } if (_customerSettings.UsernamesEnabled && model.Username != null) { model.Username = model.Username.Trim(); } customer.AffiliateId = Sponsors.Id; customer.SponsorsName = model.SponsorsName; bool isApproved = _customerSettings.UserRegistrationType == UserRegistrationType.Standard; var registrationRequest = new CustomerRegistrationRequest(customer, model.Email, _customerSettings.UsernamesEnabled ? model.Username : model.Email, model.Password, _customerSettings.DefaultPasswordFormat, isApproved); var registrationResult = _customerRegistrationService.RegisterCustomer(registrationRequest); if (registrationResult.Success) { // properties if (_dateTimeSettings.AllowCustomersToSetTimeZone) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.TimeZoneId, model.TimeZoneId); } // form fields if (_customerSettings.GenderEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Gender, model.Gender); } _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.FirstName, model.FirstName); _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.LastName, model.LastName); if (_customerSettings.DateOfBirthEnabled) { DateTime?dateOfBirth = null; try { dateOfBirth = new DateTime(model.DateOfBirthYear.Value, model.DateOfBirthMonth.Value, model.DateOfBirthDay.Value); } catch { } _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.DateOfBirth, dateOfBirth); } if (_customerSettings.CountryEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.CountryId, model.CountryId); } if (_customerSettings.PhoneEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Phone, model.Phone); } if (_customerSettings.CustomerNumberMethod == CustomerNumberMethod.AutomaticallySet && String.IsNullOrEmpty(customer.GetAttribute <string>(SystemCustomerAttributeNames.CustomerNumber))) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.CustomerNumber, customer.Id); } // Notifications if (_customerSettings.NotifyNewCustomerRegistration) { Services.MessageFactory.SendCustomerRegisteredNotificationMessage(customer, _localizationSettings.DefaultAdminLanguageId); } Services.MessageFactory.SendCustomerWelcomeMessage(customer, _workContext.WorkingLanguage.Id); if (_customerSettings.UserRegistrationType == UserRegistrationType.EmailValidation) { // email validation message _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.AccountActivationToken, Guid.NewGuid().ToString()); Services.MessageFactory.SendCustomerEmailValidationMessage(customer, _workContext.WorkingLanguage.Id); var subscription = new NewsLetterSubscription { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = customer.Email, Active = false, CreatedOnUtc = DateTime.UtcNow, StoreId = _storeContext.CurrentStore.Id }; _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); //return RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation }); return(Request.CreateResponse(HttpStatusCode.OK, new { code = 1, Message = _localizationService.GetResource("Customer.VerifyEmail") })); } else if (_customerSettings.UserRegistrationType == UserRegistrationType.AdminApproval) { return(Request.CreateResponse(HttpStatusCode.OK, new { code = 0, Message = _localizationService.GetResource("Customer.AdminApproval") })); } else { return(Request.CreateResponse(HttpStatusCode.OK, new { code = 0, Message = "success", GUID = customer.CustomerGuid })); } } else { return(Request.CreateResponse(HttpStatusCode.OK, new { code = 0, Message = registrationResult.Errors[0] })); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, new { code = 1, Message = "Something went wrong, Ex:" + ex.ToString() })); } }
/// <summary> /// Inserts a newsletter subscription /// </summary> /// <param name="newsLetterSubscription">NewsLetter subscription</param> /// <param name="publishSubscriptionEvents">if set to <c>true</c> [publish subscription events].</param> public void InsertNewsLetterSubscription(NewsLetterSubscription newsLetterSubscription, bool publishSubscriptionEvents = true) { _newsLetterSubscriptionService.InsertNewsLetterSubscription(newsLetterSubscription, publishSubscriptionEvents); }
/// <summary> /// Import newsletter subscribers from TXT file /// </summary> /// <param name="stream">Stream</param> /// <returns>Number of imported subscribers</returns> public virtual int ImportNewsletterSubscribersFromTxt(Stream stream) { int count = 0; using (var reader = new StreamReader(stream)) { while (!reader.EndOfStream) { string line = reader.ReadLine(); if (String.IsNullOrWhiteSpace(line)) { continue; } string[] tmp = line.Split(','); var email = ""; bool isActive = true; int storeId = _storeContext.CurrentStore.Id; //parse if (tmp.Length == 1) { //"email" only email = tmp[0].Trim(); } else if (tmp.Length == 2) { //"email" and "active" fields specified email = tmp[0].Trim(); isActive = Boolean.Parse(tmp[1].Trim()); } else if (tmp.Length == 3) { //"email" and "active" and "storeId" fields specified email = tmp[0].Trim(); isActive = Boolean.Parse(tmp[1].Trim()); storeId = Int32.Parse(tmp[2].Trim()); } else { throw new NopException("Wrong file format"); } //import var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(email, storeId); if (subscription != null) { subscription.Email = email; subscription.Active = isActive; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); } else { subscription = new NewsLetterSubscription { Active = isActive, CreatedOnUtc = DateTime.UtcNow, Email = email, StoreId = storeId, NewsLetterSubscriptionGuid = Guid.NewGuid() }; _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); } count++; } } return(count); }
public HttpResponseMessage Subscribe(int customerid, bool subscribe, string email, int id = 0) { var response = this.Request.CreateResponse(); var customer = _customerServices.GetCustomerById(customerid); if (customerid != 0) { _services.WorkContext.CurrentCustomer = customer; } string jsonString = ""; try { string result = ""; var success = false; if (!email.IsEmail()) { result = T("Newsletter.Email.Wrong"); } else { // subscribe/unsubscribe email = email.Trim(); _workContext.CurrentCustomer = (customer != null) ? customer : _customerServices.GetCustomerById(id); var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email, _storeContext.CurrentStore.Id); if (subscription != null) { if (subscribe) { if (!subscription.Active) { Services.MessageFactory.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); result = T("Newsletter.SubscribeEmailSent"); } else { result = T("Newsletter.AllReadysubscribed"); } } else { if (subscription.Active) { Services.MessageFactory.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id); result = T("Newsletter.UnsubscribeEmailSent"); } else { result = T("Newsletter.AllReadyunsubscribed"); } } } else { if (subscribe) { subscription = new NewsLetterSubscription { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = email, Active = false, CreatedOnUtc = DateTime.UtcNow, StoreId = _storeContext.CurrentStore.Id }; _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); Services.MessageFactory.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); result = T("Newsletter.SubscribeEmailSent"); } else { result = T("Newsletter.SubscribscribtionNotFound"); } } } jsonString = JsonConvert.SerializeObject(result, Formatting.None); jsonString = "{\"code\":1,\"message\": \"success\",\"data\":" + jsonString + "}"; response.StatusCode = HttpStatusCode.OK; response.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); return(response); } catch (Exception ex) { jsonString = "{\"code\": 0,\"message\": \"" + _localizationService.GetResource("Common.SomethingWentWrong") + "\"}"; response.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); return(response); } }
public JsonResult SubscribeNewsletter(NewsletterBoxModel model) { string result; bool success = false; var email = model.Email; var subscribe = model.Subscribe; if (!CommonHelper.IsValidEmail(email)) { result = _localizationService.GetResource("Newsletter.Email.Wrong"); } else { //subscribe/unsubscribe email = email.Trim(); var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email); if (subscription != null) { if (subscribe) { if (!subscription.Active) { _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingCurrency.Id); } result = _localizationService.GetResource("Newsletter.SubscribeEmailSent"); } else { if (subscription.Active) { _workflowMessageService.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id); } result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent"); } } else if (subscribe) { subscription = new NewsLetterSubscription() { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = email, FirstName = model.FirstName, LastName = model.LastName, Gender = model.Gender, Active = true, CreatedOnUtc = DateTime.UtcNow, LanguageId = _workContext.WorkingLanguage.Id }; _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); //_workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); //result = _localizationService.GetResource("Newsletter.SubscribeEmailSent"); } else { //result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent"); } success = true; } return(Json(new { Success = success })); }
public async Task <SubscribeNewsletterResultModel> Handle(SubscribeNewsletterCommand request, CancellationToken cancellationToken) { var model = new SubscribeNewsletterResultModel(); var email = request.Email; if (!CommonHelper.IsValidEmail(email)) { model.Result = _translationService.GetResource("Newsletter.Email.Wrong"); } else { email = email.Trim(); var subscription = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(email, _workContext.CurrentStore.Id); if (subscription != null) { if (request.Subscribe) { if (!subscription.Active) { await _messageProviderService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); } model.Result = _translationService.GetResource("Newsletter.SubscribeEmailSent"); } else { if (subscription.Active) { await _messageProviderService.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id); } model.Result = _translationService.GetResource("Newsletter.UnsubscribeEmailSent"); } } else if (request.Subscribe) { subscription = new NewsLetterSubscription { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = email, CustomerId = _workContext.CurrentCustomer.Id, Active = false, StoreId = _workContext.CurrentStore.Id, CreatedOnUtc = DateTime.UtcNow }; await _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); await _messageProviderService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); model.Result = _translationService.GetResource("Newsletter.SubscribeEmailSent"); var modelCategory = await PrepareNewsletterCategory(subscription.Id); if (modelCategory.NewsletterCategories.Count > 0) { model.NewsletterCategory = modelCategory; } } else { model.Result = _translationService.GetResource("Newsletter.UnsubscribeEmailSent"); } model.Success = true; } return(model); }
public async Task <bool> Handle(CustomerRegisteredCommand request, CancellationToken cancellationToken) { //VAT number if (_taxSettings.EuVatEnabled) { await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.VatNumber, request.Model.VatNumber); var vat = await _checkVatService.GetVatNumberStatus(request.Model.VatNumber); await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.VatNumberStatusId, (int)vat.status); } //form fields if (_customerSettings.GenderEnabled) { await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Gender, request.Model.Gender); } await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.FirstName, request.Model.FirstName); await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.LastName, request.Model.LastName); if (_customerSettings.DateOfBirthEnabled) { DateTime?dateOfBirth = request.Model.ParseDateOfBirth(); await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.DateOfBirth, dateOfBirth); } if (_customerSettings.CompanyEnabled) { await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Company, request.Model.Company); } if (_customerSettings.StreetAddressEnabled) { await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StreetAddress, request.Model.StreetAddress); } if (_customerSettings.StreetAddress2Enabled) { await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StreetAddress2, request.Model.StreetAddress2); } if (_customerSettings.ZipPostalCodeEnabled) { await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.ZipPostalCode, request.Model.ZipPostalCode); } if (_customerSettings.CityEnabled) { await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.City, request.Model.City); } if (_customerSettings.CountryEnabled) { await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.CountryId, request.Model.CountryId); } if (_customerSettings.CountryEnabled && _customerSettings.StateProvinceEnabled) { await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StateProvinceId, request.Model.StateProvinceId); } if (_customerSettings.PhoneEnabled) { await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Phone, request.Model.Phone); } if (_customerSettings.FaxEnabled) { await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Fax, request.Model.Fax); } //newsletter if (_customerSettings.NewsletterEnabled) { var categories = new List <string>(); foreach (string formKey in request.Form.Keys) { if (formKey.Contains("customernewsletterCategory_")) { try { var category = formKey.Split('_')[1]; categories.Add(category); } catch { } } } //save newsletter value var newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(request.Model.Email, request.Store.Id); if (newsletter != null) { newsletter.Categories.Clear(); categories.ForEach(x => newsletter.Categories.Add(x)); if (request.Model.Newsletter) { newsletter.Active = true; await _newsLetterSubscriptionService.UpdateNewsLetterSubscription(newsletter); } } else { if (request.Model.Newsletter) { var newsLetterSubscription = new NewsLetterSubscription { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = request.Model.Email, CustomerId = request.Customer.Id, Active = true, StoreId = request.Store.Id, CreatedOnUtc = DateTime.UtcNow }; categories.ForEach(x => newsLetterSubscription.Categories.Add(x)); await _newsLetterSubscriptionService.InsertNewsLetterSubscription(newsLetterSubscription); } } } //save customer attributes await _customerService.UpdateCustomerField(request.Customer, x => x.Attributes, request.CustomerAttributes); //insert default address (if possible) var defaultAddress = new Address { FirstName = request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.FirstName), LastName = request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.LastName), Email = request.Customer.Email, Company = request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.Company), VatNumber = request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.VatNumber), CountryId = !string.IsNullOrEmpty(request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.CountryId)) ? request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.CountryId) : "", StateProvinceId = !string.IsNullOrEmpty(request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.StateProvinceId)) ? request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.StateProvinceId) : "", City = request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.City), Address1 = request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.StreetAddress), Address2 = request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.StreetAddress2), ZipPostalCode = request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.ZipPostalCode), PhoneNumber = request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.Phone), FaxNumber = request.Customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.Fax), CreatedOnUtc = request.Customer.CreatedOnUtc, }; if (await IsAddressValid(defaultAddress)) { //set default address request.Customer.Addresses.Add(defaultAddress); await _customerService.InsertAddress(defaultAddress, request.Customer.Id); request.Customer.BillingAddress = defaultAddress; await _customerService.UpdateBillingAddress(defaultAddress, request.Customer.Id); request.Customer.ShippingAddress = defaultAddress; await _customerService.UpdateShippingAddress(defaultAddress, request.Customer.Id); } //notifications if (_customerSettings.NotifyNewCustomerRegistration) { await _messageProviderService.SendCustomerRegisteredMessage(request.Customer, request.Store, _languageSettings.DefaultAdminLanguageId); } //New customer has a free shipping for the first order if (_customerSettings.RegistrationFreeShipping) { await _customerService.UpdateCustomerField(request.Customer, x => x.FreeShipping, true); } await _customerActionEventService.Registration(request.Customer); return(true); }
public virtual SubscribeNewsletterResultModel SubscribeNewsletter(string email, bool subscribe) { var model = new SubscribeNewsletterResultModel(); if (!CommonHelper.IsValidEmail(email)) { model.Result = _localizationService.GetResource("Newsletter.Email.Wrong"); } else { email = email.Trim(); var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(email, _storeContext.CurrentStore.Id); if (subscription != null) { if (subscribe) { if (!subscription.Active) { _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); } model.Result = _localizationService.GetResource("Newsletter.SubscribeEmailSent"); } else { if (subscription.Active) { _workflowMessageService.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id); } model.Result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent"); } } else if (subscribe) { subscription = new NewsLetterSubscription { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = email, CustomerId = _workContext.CurrentCustomer.Id, Active = false, StoreId = _storeContext.CurrentStore.Id, CreatedOnUtc = DateTime.UtcNow }; _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); model.Result = _localizationService.GetResource("Newsletter.SubscribeEmailSent"); var modelCategory = PrepareNewsletterCategory(subscription.Id); if (modelCategory.NewsletterCategories.Count > 0) { model.NewsletterCategory = modelCategory; } } else { model.Result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent"); } model.Success = true; } return(model); }
public virtual ActionResult Register(PaaMember member, string returnUrl, bool captchaValid, FormCollection form) { RegisterModel model = null;// = member.RegisterModel; //check whether registration is allowed if (_customerSettings.UserRegistrationType == UserRegistrationType.Disabled) { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Disabled })); } if (_workContext.CurrentCustomer.IsRegistered()) { //Already registered customer. _authenticationService.SignOut(); //raise logged out event _eventPublisher.Publish(new CustomerLoggedOutEvent(_workContext.CurrentCustomer)); //Save a new record _workContext.CurrentCustomer = _customerService.InsertGuestCustomer(); } var customer = _workContext.CurrentCustomer; customer.RegisteredInStoreId = _storeContext.CurrentStore.Id; //custom customer attributes var customerAttributesXml = ParseCustomCustomerAttributes(form); var customerAttributeWarnings = _customerAttributeParser.GetAttributeWarnings(customerAttributesXml); foreach (var error in customerAttributeWarnings) { ModelState.AddModelError("", error); } //validate CAPTCHA if (_captchaSettings.Enabled && _captchaSettings.ShowOnRegistrationPage && !captchaValid) { ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService)); } if (ModelState.IsValid) { if (_customerSettings.UsernamesEnabled && model.Username != null) { model.Username = model.Username.Trim(); } bool isApproved = _customerSettings.UserRegistrationType == UserRegistrationType.Standard; var registrationRequest = new CustomerRegistrationRequest(customer, model.Email, _customerSettings.UsernamesEnabled ? model.Username : model.Email, model.Password, _customerSettings.DefaultPasswordFormat, _storeContext.CurrentStore.Id, isApproved); var registrationResult = _customerRegistrationService.RegisterCustomer(registrationRequest); if (registrationResult.Success) { //properties if (_dateTimeSettings.AllowCustomersToSetTimeZone) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.TimeZoneId, model.TimeZoneId); } //VAT number if (_taxSettings.EuVatEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.VatNumber, model.VatNumber); string vatName; string vatAddress; var vatNumberStatus = _taxService.GetVatNumberStatus(model.VatNumber, out vatName, out vatAddress); _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.VatNumberStatusId, (int)vatNumberStatus); //send VAT number admin notification if (!String.IsNullOrEmpty(model.VatNumber) && _taxSettings.EuVatEmailAdminWhenNewVatSubmitted) { _workflowMessageService.SendNewVatSubmittedStoreOwnerNotification(customer, model.VatNumber, vatAddress, _localizationSettings.DefaultAdminLanguageId); } } //form fields if (_customerSettings.GenderEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Gender, model.Gender); } _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.FirstName, model.FirstName); _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.LastName, model.LastName); if (_customerSettings.DateOfBirthEnabled) { // DateTime? dateOfBirth = model.ParseDateOfBirth(); // _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.DateOfBirth, dateOfBirth); } if (_customerSettings.CompanyEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Company, model.Company); } if (_customerSettings.StreetAddressEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StreetAddress, model.StreetAddress); } if (_customerSettings.StreetAddress2Enabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StreetAddress2, model.StreetAddress2); } if (_customerSettings.ZipPostalCodeEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.ZipPostalCode, model.ZipPostalCode); } if (_customerSettings.CityEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.City, model.City); } if (_customerSettings.CountryEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.CountryId, model.CountryId); } if (_customerSettings.CountryEnabled && _customerSettings.StateProvinceEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StateProvinceId, model.StateProvinceId); } if (_customerSettings.PhoneEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Phone, model.Phone); } if (_customerSettings.FaxEnabled) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Fax, model.Fax); } //newsletter if (_customerSettings.NewsletterEnabled) { //save newsletter value var newsletter = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(model.Email, _storeContext.CurrentStore.Id); if (newsletter != null) { if (model.Newsletter) { newsletter.Active = true; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(newsletter); } //else //{ //When registering, not checking the newsletter check box should not take an existing email address off of the subscription list. //_newsLetterSubscriptionService.DeleteNewsLetterSubscription(newsletter); //} } else { if (model.Newsletter) { _newsLetterSubscriptionService.InsertNewsLetterSubscription(new NewsLetterSubscription { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = model.Email, Active = true, StoreId = _storeContext.CurrentStore.Id, CreatedOnUtc = DateTime.UtcNow }); } } } //save customer attributes _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.CustomCustomerAttributes, customerAttributesXml); //login customer now if (isApproved) { _authenticationService.SignIn(customer, true); } //associated with external account (if possible) TryAssociateAccountWithExternalAccount(customer); //insert default address (if possible) var defaultAddress = new Address { FirstName = customer.GetAttribute <string>(SystemCustomerAttributeNames.FirstName), LastName = customer.GetAttribute <string>(SystemCustomerAttributeNames.LastName), Email = customer.Email, Company = customer.GetAttribute <string>(SystemCustomerAttributeNames.Company), CountryId = customer.GetAttribute <int>(SystemCustomerAttributeNames.CountryId) > 0 ? (int?)customer.GetAttribute <int>(SystemCustomerAttributeNames.CountryId) : null, StateProvinceId = customer.GetAttribute <int>(SystemCustomerAttributeNames.StateProvinceId) > 0 ? (int?)customer.GetAttribute <int>(SystemCustomerAttributeNames.StateProvinceId) : null, City = customer.GetAttribute <string>(SystemCustomerAttributeNames.City), Address1 = customer.GetAttribute <string>(SystemCustomerAttributeNames.StreetAddress), Address2 = customer.GetAttribute <string>(SystemCustomerAttributeNames.StreetAddress2), ZipPostalCode = customer.GetAttribute <string>(SystemCustomerAttributeNames.ZipPostalCode), PhoneNumber = customer.GetAttribute <string>(SystemCustomerAttributeNames.Phone), FaxNumber = customer.GetAttribute <string>(SystemCustomerAttributeNames.Fax), CreatedOnUtc = customer.CreatedOnUtc }; if (this._addressService.IsAddressValid(defaultAddress)) { //some validation if (defaultAddress.CountryId == 0) { defaultAddress.CountryId = null; } if (defaultAddress.StateProvinceId == 0) { defaultAddress.StateProvinceId = null; } //set default address customer.Addresses.Add(defaultAddress); customer.BillingAddress = defaultAddress; customer.ShippingAddress = defaultAddress; _customerService.UpdateCustomer(customer); } //notifications if (_customerSettings.NotifyNewCustomerRegistration) { _workflowMessageService.SendCustomerRegisteredNotificationMessage(customer, _localizationSettings.DefaultAdminLanguageId); } //raise event _eventPublisher.Publish(new CustomerRegisteredEvent(customer)); switch (_customerSettings.UserRegistrationType) { case UserRegistrationType.EmailValidation: { //email validation message _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.AccountActivationToken, Guid.NewGuid().ToString()); _workflowMessageService.SendCustomerEmailValidationMessage(customer, _workContext.WorkingLanguage.Id); //result return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation })); } case UserRegistrationType.AdminApproval: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval })); } case UserRegistrationType.Standard: { //send customer welcome message _workflowMessageService.SendCustomerWelcomeMessage(customer, _workContext.WorkingLanguage.Id); var redirectUrl = Url.RouteUrl("RegisterResult", new { resultId = (int)UserRegistrationType.Standard }); if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl)) { redirectUrl = _webHelper.ModifyQueryString(redirectUrl, "returnurl=" + HttpUtility.UrlEncode(returnUrl), null); } return(Redirect(redirectUrl)); } default: { return(RedirectToRoute("HomePage")); } } } //errors foreach (var error in registrationResult.Errors) { ModelState.AddModelError("", error); } } //If we got this far, something failed, redisplay form // model = _customerModelFactory.PrepareRegisterModel( model, true, customerAttributesXml); // return View("PaidMemberShip" , model); return(null); }
public ActionResult Subscribe(bool subscribe, string email) { string result; var success = false; var customer = Services.WorkContext.CurrentCustomer; var hasConsentedToGdpr = customer.GetAttribute <bool>(SystemCustomerAttributeNames.HasConsentedToGdpr); var hasConsented = ViewData["GdprConsent"] != null ? (bool)ViewData["GdprConsent"] : hasConsentedToGdpr; if (!hasConsented && _privacySettings.Value.DisplayGdprConsentOnForms) { return(Json(new { Success = success, Result = String.Empty })); } if (!email.IsEmail()) { result = T("Newsletter.Email.Wrong"); } else { // subscribe/unsubscribe email = email.Trim(); var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email, _storeContext.CurrentStore.Id); if (subscription != null) { if (subscribe) { if (!subscription.Active) { Services.MessageFactory.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); } result = T("Newsletter.SubscribeEmailSent"); } else { if (subscription.Active) { Services.MessageFactory.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id); } result = T("Newsletter.UnsubscribeEmailSent"); } } else if (subscribe) { subscription = new NewsLetterSubscription { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = email, Active = false, CreatedOnUtc = DateTime.UtcNow, StoreId = _storeContext.CurrentStore.Id, WorkingLanguageId = _workContext.WorkingLanguage.Id }; _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); Services.MessageFactory.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); result = T("Newsletter.SubscribeEmailSent"); } else { result = T("Newsletter.UnsubscribeEmailSent"); } success = true; } return(Json(new { Success = success, Result = result, })); }
public ActionResult SubscribeNewsletter(bool subscribe, string email) { string result; bool success = false; if (!email.IsEmail()) { result = _localizationService.GetResource("Newsletter.Email.Wrong"); } else { //subscribe/unsubscribe email = email.Trim(); var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email); if (subscription != null) { if (subscribe) { if (!subscription.Active) { _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); } result = _localizationService.GetResource("Newsletter.SubscribeEmailSent"); } else { if (subscription.Active) { _workflowMessageService.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id); } result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent"); } } else if (subscribe) { subscription = new NewsLetterSubscription() { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = email, Active = false, CreatedOnUtc = DateTime.UtcNow }; _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); result = _localizationService.GetResource("Newsletter.SubscribeEmailSent"); } else { result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent"); } success = true; } return(Json(new { Success = success, Result = result, })); }
public ActionResult ImportCsv(FormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers)) { return(AccessDeniedView()); } try { var file = Request.Files["importcsvfile"]; if (file != null && file.ContentLength > 0) { int count = 0; using (var reader = new StreamReader(file.InputStream)) { while (!reader.EndOfStream) { string line = reader.ReadLine(); if (String.IsNullOrWhiteSpace(line)) { continue; } string[] tmp = line.Split(','); var email = ""; bool isActive = true; int storeId = _storeContext.CurrentStore.Id; //parse if (tmp.Length == 1) { //"email" only email = tmp[0].Trim(); } else if (tmp.Length == 2) { //"email" and "active" fields specified email = tmp[0].Trim(); isActive = Boolean.Parse(tmp[1].Trim()); } else if (tmp.Length == 3) { //"email" and "active" and "storeId" fields specified email = tmp[0].Trim(); isActive = Boolean.Parse(tmp[1].Trim()); storeId = Int32.Parse(tmp[2].Trim()); } else { throw new NopException("Wrong file format"); } //import var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(email, storeId); if (subscription != null) { subscription.Email = email; subscription.Active = isActive; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); } else { subscription = new NewsLetterSubscription() { Active = isActive, CreatedOnUtc = DateTime.UtcNow, Email = email, StoreId = storeId, NewsLetterSubscriptionGuid = Guid.NewGuid() }; _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); } count++; } SuccessNotification(String.Format(_localizationService.GetResource("Admin.Promotions.NewsLetterSubscriptions.ImportEmailsSuccess"), count)); return(RedirectToAction("List")); } } ErrorNotification(_localizationService.GetResource("Admin.Common.UploadFile")); return(RedirectToAction("List")); } catch (Exception exc) { ErrorNotification(exc); return(RedirectToAction("List")); } }
public ActionResult ImportCsv(FormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers)) { return(AccessDeniedView()); } try { var file = Request.Files["importcsvfile"]; if (file != null && file.ContentLength > 0) { int count = 0; using (var reader = new StreamReader(file.InputStream)) { while (!reader.EndOfStream) { string line = reader.ReadLine(); string[] tmp = line.Split('\t'); if (tmp.Length == 2) { string email = tmp[0].Trim(); bool isActive = Boolean.Parse(tmp[1]); var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email); if (subscription != null) { subscription.Email = email; subscription.Active = isActive; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); } else { subscription = new NewsLetterSubscription() { Active = isActive, CreatedOnUtc = DateTime.UtcNow, Email = email, NewsLetterSubscriptionGuid = Guid.NewGuid() }; _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); } count++; } } SuccessNotification( String.Format( _localizationService.GetResource( "Admin.Promotions.NewsLetterSubscriptions.ImportEmailsSuccess"), count)) ; return(RedirectToAction("List")); } } ErrorNotification("Please upload a file"); return(RedirectToAction("List")); } catch (Exception exc) { ErrorNotification(exc); return(RedirectToAction("List")); } }
public ActionResult Subscribe(bool subscribe, string email) { string result; var success = false; if (!email.IsEmail()) { result = T("Newsletter.Email.Wrong"); } else { //subscribe/unsubscribe email = email.Trim(); var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email, _storeContext.CurrentStore.Id); if (subscription != null) { if (subscribe) { if (!subscription.Active) { Services.MessageFactory.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); } result = T("Newsletter.SubscribeEmailSent"); } else { if (subscription.Active) { Services.MessageFactory.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id); } result = T("Newsletter.UnsubscribeEmailSent"); } } else if (subscribe) { subscription = new NewsLetterSubscription { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = email, Active = false, CreatedOnUtc = DateTime.UtcNow, StoreId = _storeContext.CurrentStore.Id }; _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); Services.MessageFactory.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id); result = T("Newsletter.SubscribeEmailSent"); } else { result = T("Newsletter.UnsubscribeEmailSent"); } success = true; } return(Json(new { Success = success, Result = result, })); }
public ActionResult CampaignRegister(NewsletterBoxModel model) { var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(model.CampaignMail); if (model.CampaignMail != null) { if (subscription == null) { NewsLetterSubscription subscriptionmodel = new NewsLetterSubscription(); // İlk üyelik için. tüm alanlar doldurulur. subscriptionmodel.Active = false; subscriptionmodel.CountryId = model.CountryId; subscriptionmodel.CreatedOnUtc = DateTime.Now; subscriptionmodel.Email = model.CampaignMail; subscriptionmodel.FirstName = model.FirstName; subscriptionmodel.LastName = model.LastName; subscriptionmodel.Gender = model.Gender; subscriptionmodel.LanguageId = _workContext.WorkingLanguage.Id; subscriptionmodel.RegistrationType = "Campaign"; subscriptionmodel.NewsLetterSubscriptionGuid = Guid.NewGuid(); _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscriptionmodel); _workflowMessageService.SendCampaignRegisterActivationMessage(subscriptionmodel, _workContext.WorkingLanguage.Id); return(RedirectToAction("CampaignFriendsConvoke", new { id = subscriptionmodel.Id })); } else if (subscription != null && subscription.RegistrationType != "Campaign") // Önceden newsletterdaki kayıtlar için { subscription.Active = true; subscription.Gender = model.Gender; subscription.CountryId = model.CountryId; subscription.FirstName = model.FirstName; subscription.LastName = model.LastName; subscription.RegistrationType = "Campaign"; subscription.LanguageId = _workContext.WorkingLanguage.Id; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); //_workflowMessageService.SendCampaignRegisterActivationMessage(subscription, _workContext.WorkingLanguage.Id); return(RedirectToAction("CampaignFriendsConvoke", new { id = subscription.Id })); } else // Davetiye maili ile gelenler için { subscription.Email = model.CampaignMail; subscription.Active = false; subscription.CountryId = model.CountryId; subscription.LanguageId = _workContext.WorkingLanguage.Id; subscription.Gender = model.Gender; subscription.FirstName = model.FirstName; subscription.LastName = model.LastName; subscription.RegistrationType = "Campaign"; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); _workflowMessageService.SendCampaignRegisterActivationMessage(subscription, _workContext.WorkingLanguage.Id); return(RedirectToAction("CampaignFriendsConvoke", new { id = subscription.Id })); } } if (subscription != null) { return(RedirectToRoute("CampaingRegisterConvoke", new { id = subscription.Id })); } else { return(RedirectToRoute("HomePage")); } } // İlk kayıt ekranı