private async Task UpdateNewsletter(UpdateCustomerInfoCommand request) { 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.Customer.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 { newsletter.Active = false; await _newsLetterSubscriptionService.UpdateNewsLetterSubscription(newsletter); } } else { if (request.Model.Newsletter) { var newsLetterSubscription = new NewsLetterSubscription { NewsLetterSubscriptionGuid = Guid.NewGuid(), Email = request.Customer.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); } } }
public ActionResult SubscriptionUpdate(NewsLetterSubscriptionModel model, GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers)) { return(AccessDeniedView()); } var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(model.Id); subscription.Email = model.Email; subscription.Active = model.Active; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); return(SubscriptionList(command, new NewsLetterSubscriptionListModel())); }
public ActionResult SubscriptionActivation(Guid token, bool active) { var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByGuid(token); if (subscription == null) { return(HttpNotFound()); } var model = new SubscriptionActivationModel(); if (active) { subscription.Active = active; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); } else { _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription); } model.Result = T(active ? "Newsletter.ResultActivated" : "Newsletter.ResultDeactivated"); return(View(model)); }
public ActionResult SubscriptionActivation(Guid token, bool active) { var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByGuid(token); if (subscription == null) { return(RedirectToRoute("HomePage")); } var model = new SubscriptionActivationModel(); if (active) { subscription.Active = active; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); } else { _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription); } if (active) { model.Result = _localizationService.GetResource("Newsletter.ResultActivated"); } else { model.Result = _localizationService.GetResource("Newsletter.ResultDeactivated"); } return(View(model)); }
public ActionResult SubscriptionUpdate(NewsLetterSubscriptionModel model, GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { //display the first model error var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage); return(Content(modelStateErrors.FirstOrDefault())); } var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(model.Id); subscription.Email = model.Email; subscription.Active = model.Active; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); var listModel = new NewsLetterSubscriptionListModel(); PrepareNewsLetterSubscriptionListModel(listModel); return(SubscriptionList(command, listModel)); }
public async Task <SubscriptionActivationModel> Handle(SubscriptionActivationCommand request, CancellationToken cancellationToken) { var subscription = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByGuid(request.Token); if (subscription == null) { return(null); } var model = new SubscriptionActivationModel(); if (request.Active) { subscription.Active = true; await _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); } else { await _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription); } model.Result = request.Active ? _translationService.GetResource("Newsletter.ResultActivated") : _translationService.GetResource("Newsletter.ResultDeactivated"); return(model); }
public async Task UpdateNewsLetterSubscription_InvokeRepository() { var email = "*****@*****.**"; var newsLetterSubscription = new NewsLetterSubscription() { Email = email, Active = false }; await _newsLetterSubscriptionService.UpdateNewsLetterSubscription(newsLetterSubscription); _subscriptionRepository.Verify(r => r.UpdateAsync(newsLetterSubscription), Times.Once); _historyServiceMock.Verify(h => h.SaveObject(It.IsAny <BaseEntity>()), Times.Once); _mediatorMock.Verify(c => c.Publish(It.IsAny <EntityUpdated <NewsLetterSubscription> >(), default(CancellationToken)), Times.Once); }
public ActionResult SubscriptionUpdate([Bind(Exclude = "CreatedOn")] NewsLetterSubscriptionModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(Json(new DataSourceResult() { Errors = ModelState.SerializeErrors() })); } var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(model.Id); subscription.Email = model.Email; subscription.Active = model.Active; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); return(new NullJsonResult()); }
/// <summary> /// Sets a user email /// </summary> /// <param name="customer">Customer</param> /// <param name="newEmail">New email</param> public virtual async Task SetEmail(Customer customer, string newEmail) { if (customer == null) { throw new ArgumentNullException("customer"); } if (newEmail == null) { throw new GrandException("Email cannot be null"); } newEmail = newEmail.Trim(); string oldEmail = customer.Email; if (!CommonHelper.IsValidEmail(newEmail)) { throw new GrandException(_localizationService.GetResource("Account.EmailUsernameErrors.NewEmailIsNotValid")); } if (newEmail.Length > 100) { throw new GrandException(_localizationService.GetResource("Account.EmailUsernameErrors.EmailTooLong")); } var customer2 = await _customerService.GetCustomerByEmail(newEmail); if (customer2 != null && customer.Id != customer2.Id) { throw new GrandException(_localizationService.GetResource("Account.EmailUsernameErrors.EmailAlreadyExists")); } customer.Email = newEmail; await _customerService.UpdateCustomer(customer); //update newsletter subscription (if required) if (!String.IsNullOrEmpty(oldEmail) && !oldEmail.Equals(newEmail, StringComparison.OrdinalIgnoreCase)) { foreach (var store in await _storeService.GetAllStores()) { var subscriptionOld = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(oldEmail, store.Id); if (subscriptionOld != null) { subscriptionOld.Email = newEmail; await _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscriptionOld); } } } }
public ActionResult SubscriptionActivation(Guid token, bool active) { var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByGuid(token); if (subscription == null) { return(RedirectToAction("Index", "Home")); } var model = new SubscriptionActivationModel(); if (active) { subscription.Active = active; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); if (subscription.RegistrationType == "promoted5") { StatefulStorage.PerSession.Add <Guid>("newslettersubscriptiontoken", () => token); return(RedirectToAction("NewsletterPromotedDynasty")); } } else { _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription); } if (active) { model.Result = _localizationService.GetResource("Newsletter.ResultActivated"); } else { model.Result = _localizationService.GetResource("Newsletter.ResultDeactivated"); } return(View(model)); }
public virtual async Task <IActionResult> SaveCategories(IFormCollection form) { bool success = false; string message = string.Empty; var newsletterEmailId = form["NewsletterEmailId"].ToString(); if (!string.IsNullOrEmpty(newsletterEmailId)) { var subscription = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(newsletterEmailId); if (subscription != null) { foreach (string formKey in form.Keys) { if (formKey.Contains("Category_")) { try { var category = formKey.Split('_')[1]; subscription.Categories.Add(category); } catch (Exception ex) { message = ex.Message; } } } success = true; await _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription, false); } else { message = "Email not exist"; } } else { message = "Empty NewsletterEmailId"; } return(Json(new { Success = success, Message = message })); }
public async Task <IActionResult> SubscriptionUpdate(NewsLetterSubscriptionModel model) { if (!ModelState.IsValid) { return(Json(new DataSourceResult { Errors = ModelState.SerializeErrors() })); } var subscription = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(model.Id); subscription.Email = model.Email; subscription.Active = model.Active; await _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); return(new NullJsonResult()); }
public virtual async Task <SubscriptionActivationModel> PrepareSubscriptionActivation(NewsLetterSubscription subscription, bool active) { var model = new SubscriptionActivationModel(); if (active) { subscription.Active = true; await _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); } else { await _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription); } model.Result = active ? _localizationService.GetResource("Newsletter.ResultActivated") : _localizationService.GetResource("Newsletter.ResultDeactivated"); return(model); }
public IActionResult DeactivateNewsLetterSubscription(string email) { if (string.IsNullOrEmpty(email)) { return(Error(HttpStatusCode.BadRequest, "The email parameter could not be empty.")); } var existingSubscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(email, _storeContext.CurrentStore.Id); if (existingSubscription == null) { return(Error(HttpStatusCode.BadRequest, "There is no news letter subscription with the specified email.")); } existingSubscription.Active = false; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(existingSubscription); return(Ok()); }
public virtual IActionResult SubscriptionUpdate(NewsletterSubscriptionModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(ErrorJson(ModelState.SerializeErrors())); } var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(model.Id); //fill entity from model subscription = model.ToEntity(subscription); _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); return(new NullJsonResult()); }
/// <summary> /// Sets a user email /// </summary> /// <param name="customer">Customer</param> /// <param name="newEmail">New email</param> public virtual void SetEmail(Customer customer, string newEmail) { if (customer == null) { throw new ArgumentNullException("customer"); } newEmail = newEmail.Trim(); string oldEmail = customer.Email; if (!newEmail.IsEmail()) { throw new SmartException(T("Account.EmailUsernameErrors.NewEmailIsNotValid")); } if (newEmail.Length > 100) { throw new SmartException(T("Account.EmailUsernameErrors.EmailTooLong")); } var customer2 = _customerService.GetCustomerByEmail(newEmail); if (customer2 != null && customer.Id != customer2.Id) { throw new SmartException(T("Account.EmailUsernameErrors.EmailAlreadyExists")); } customer.Email = newEmail; _customerService.UpdateCustomer(customer); //update newsletter subscription (if required) if (!String.IsNullOrEmpty(oldEmail) && !oldEmail.Equals(newEmail, StringComparison.InvariantCultureIgnoreCase)) { var subscriptionOld = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(oldEmail, _storeContext.CurrentStore.Id); if (subscriptionOld != null) { subscriptionOld.Email = newEmail; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscriptionOld); } } }
/// <summary> /// Sets a user email /// </summary> /// <param name="customer">Customer</param> /// <param name="newEmail">New email</param> public virtual void SetEmail(Customer customer, string newEmail) { if (customer == null) { throw new ArgumentNullException("customer"); } newEmail = newEmail.Trim(); string oldEmail = customer.Email; if (!CommonHelper.IsValidEmail(newEmail)) { throw new NopException("New email is not valid"); } if (newEmail.Length > 100) { throw new NopException("E-mail address is too long."); } var customer2 = GetCustomerByEmail(newEmail); if (customer2 != null && customer.Id != customer2.Id) { throw new NopException("The e-mail address is already in use."); } customer.Email = newEmail; UpdateCustomer(customer); //update newsletter subscription (if required) if (!String.IsNullOrEmpty(oldEmail) && !oldEmail.Equals(newEmail, StringComparison.InvariantCultureIgnoreCase)) { var subscriptionOld = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(oldEmail); if (subscriptionOld != null) { subscriptionOld.Email = newEmail; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscriptionOld); } } }
/// <summary> /// Sets a user email /// </summary> /// <param name="User">User</param> /// <param name="newEmail">New email</param> public virtual void SetEmail(User User, string newEmail) { if (User == null) { throw new ArgumentNullException("User"); } newEmail = newEmail.Trim(); string oldEmail = User.Email; if (!newEmail.IsEmail()) { throw new WorkException(_localizationService.GetResource("Account.EmailUserNameErrors.NewEmailIsNotValid")); } if (newEmail.Length > 100) { throw new WorkException(_localizationService.GetResource("Account.EmailUserNameErrors.EmailTooLong")); } var User2 = _userService.GetUserByEmail(newEmail); if (User2 != null && User.Id != User2.Id) { throw new WorkException(_localizationService.GetResource("Account.EmailUserNameErrors.EmailAlreadyExists")); } User.Email = newEmail; _userService.UpdateUser(User); //update newsletter subscription (if required) if (!String.IsNullOrEmpty(oldEmail) && !oldEmail.Equals(newEmail, StringComparison.InvariantCultureIgnoreCase)) { var subscriptionOld = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(oldEmail); if (subscriptionOld != null) { subscriptionOld.Email = newEmail; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscriptionOld); } } }
public ActionResult SubscriptionUpdate(NewsLetterSubscriptionModel model, GridCommand command) { if (!ModelState.IsValid) { var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage); return(Content(modelStateErrors.FirstOrDefault())); } var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(model.Id); subscription.Email = model.Email; subscription.Active = model.Active; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); var listModel = new NewsLetterSubscriptionListModel(); PrepareNewsLetterSubscriptionListModel(listModel); return(SubscriptionList(command, listModel)); }
public virtual Models.Newsletter.SubscriptionActivationModel SubscriptionActivation(Guid token, bool active) { var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByGuid(token); if (subscription == null) { return(null); } if (active) { subscription.Active = true; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); } else { _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription); } var model = _newsletterModelFactory.PrepareSubscriptionActivationModel(active); return(model); }
public virtual ActionResult SubscriptionActivation(Guid token, bool active) { var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByGuid(token); if (subscription == null) { return(RedirectToRoute("HomePage")); } if (active) { subscription.Active = true; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); } else { _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription); } var model = _newsletterModelFactory.PrepareSubscriptionActivationModel(active); return(View(model)); }
public async Task <bool> Handle(CustomerRegisteredCommand request, CancellationToken cancellationToken) { //properties if (_dateTimeSettings.AllowCustomersToSetTimeZone) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.TimeZoneId, request.Model.TimeZoneId); } //VAT number if (_taxSettings.EuVatEnabled) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.VatNumber, request.Model.VatNumber); var vat = await _checkVatService.GetVatNumberStatus(request.Model.VatNumber); await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.VatNumberStatusId, (int)vat.status); //send VAT number admin notification if (!String.IsNullOrEmpty(request.Model.VatNumber) && _taxSettings.EuVatEmailAdminWhenNewVatSubmitted) { await _workflowMessageService.SendNewVatSubmittedStoreOwnerNotification(request.Customer, request.Store, request.Model.VatNumber, vat.address, _localizationSettings.DefaultAdminLanguageId); } } //form fields if (_customerSettings.GenderEnabled) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.Gender, request.Model.Gender); } await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.FirstName, request.Model.FirstName); await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.LastName, request.Model.LastName); if (_customerSettings.DateOfBirthEnabled) { DateTime?dateOfBirth = request.Model.ParseDateOfBirth(); await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.DateOfBirth, dateOfBirth); } if (_customerSettings.CompanyEnabled) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.Company, request.Model.Company); } if (_customerSettings.StreetAddressEnabled) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.StreetAddress, request.Model.StreetAddress); } if (_customerSettings.StreetAddress2Enabled) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.StreetAddress2, request.Model.StreetAddress2); } if (_customerSettings.ZipPostalCodeEnabled) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.ZipPostalCode, request.Model.ZipPostalCode); } if (_customerSettings.CityEnabled) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.City, request.Model.City); } if (_customerSettings.CountryEnabled) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.CountryId, request.Model.CountryId); } if (_customerSettings.CountryEnabled && _customerSettings.StateProvinceEnabled) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.StateProvinceId, request.Model.StateProvinceId); } if (_customerSettings.PhoneEnabled) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.Phone, request.Model.Phone); } if (_customerSettings.FaxEnabled) { await _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.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 _genericAttributeService.SaveAttribute(request.Customer, SystemCustomerAttributeNames.CustomCustomerAttributes, request.CustomerAttributesXml); //insert default address (if possible) var defaultAddress = new Address { FirstName = request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.FirstName), LastName = request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.LastName), Email = request.Customer.Email, Company = request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.Company), VatNumber = request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.VatNumber), CountryId = !string.IsNullOrEmpty(request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.CountryId)) ? request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.CountryId) : "", StateProvinceId = !string.IsNullOrEmpty(request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.StateProvinceId)) ? request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.StateProvinceId) : "", City = request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.City), Address1 = request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.StreetAddress), Address2 = request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.StreetAddress2), ZipPostalCode = request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.ZipPostalCode), PhoneNumber = request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.Phone), FaxNumber = request.Customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.Fax), CreatedOnUtc = request.Customer.CreatedOnUtc, }; if (await _addressService.IsAddressValid(defaultAddress)) { //set default address defaultAddress.CustomerId = request.Customer.Id; request.Customer.Addresses.Add(defaultAddress); await _customerService.InsertAddress(defaultAddress); request.Customer.BillingAddress = defaultAddress; await _customerService.UpdateBillingAddress(defaultAddress); request.Customer.ShippingAddress = defaultAddress; await _customerService.UpdateShippingAddress(defaultAddress); } //notifications if (_customerSettings.NotifyNewCustomerRegistration) { await _workflowMessageService.SendCustomerRegisteredNotificationMessage(request.Customer, request.Store, _localizationSettings.DefaultAdminLanguageId); } //New customer has a free shipping for the first order if (_customerSettings.RegistrationFreeShipping) { await _customerService.UpdateFreeShipping(request.Customer.Id, true); } await _customerActionEventService.Registration(request.Customer); return(true); }
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ı
/// <summary> /// Sets a user email /// </summary> /// <param name="customer">Customer</param> /// <param name="newEmail">New email</param> /// <param name="requireValidation">Require validation of new email address</param> public virtual void SetEmail(Customer customer, string newEmail, bool requireValidation) { if (customer == null) { throw new ArgumentNullException(nameof(customer)); } if (newEmail == null) { throw new QNetException("Email cannot be null"); } newEmail = newEmail.Trim(); var oldEmail = customer.Email; if (!CommonHelper.IsValidEmail(newEmail)) { throw new QNetException(_localizationService.GetResource("Account.EmailUsernameErrors.NewEmailIsNotValid")); } if (newEmail.Length > 100) { throw new QNetException(_localizationService.GetResource("Account.EmailUsernameErrors.EmailTooLong")); } var customer2 = _customerService.GetCustomerByEmail(newEmail); if (customer2 != null && customer.Id != customer2.Id) { throw new QNetException(_localizationService.GetResource("Account.EmailUsernameErrors.EmailAlreadyExists")); } if (requireValidation) { //re-validate email customer.EmailToRevalidate = newEmail; _customerService.UpdateCustomer(customer); //email re-validation message _genericAttributeService.SaveAttribute(customer, QNetCustomerDefaults.EmailRevalidationTokenAttribute, Guid.NewGuid().ToString()); _workflowMessageService.SendCustomerEmailRevalidationMessage(customer, _workContext.WorkingLanguage.Id); } else { customer.Email = newEmail; _customerService.UpdateCustomer(customer); if (string.IsNullOrEmpty(oldEmail) || oldEmail.Equals(newEmail, StringComparison.InvariantCultureIgnoreCase)) { return; } //update newsletter subscription (if required) foreach (var store in _storeService.GetAllStores()) { var subscriptionOld = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(oldEmail, store.Id); if (subscriptionOld == null) { continue; } subscriptionOld.Email = newEmail; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscriptionOld); } } }
/// <summary> /// Sets a user email /// </summary> /// <param name="user">User</param> /// <param name="newEmail">New email</param> /// <param name="requireValidation">Require validation of new email address</param> public virtual void SetEmail(User user, string newEmail, bool requireValidation) { if (user == null) { throw new ArgumentNullException("user"); } if (newEmail == null) { throw new SysException("Email cannot be null"); } newEmail = newEmail.Trim(); string oldEmail = user.Email; if (!CommonHelper.IsValidEmail(newEmail)) { throw new SysException(_localizationService.GetResource("Account.EmailUsernameErrors.NewEmailIsNotValid")); } if (newEmail.Length > 100) { throw new SysException(_localizationService.GetResource("Account.EmailUsernameErrors.EmailTooLong")); } var user2 = _userService.GetUserByEmail(newEmail); if (user2 != null && user.Id != user2.Id) { throw new SysException(_localizationService.GetResource("Account.EmailUsernameErrors.EmailAlreadyExists")); } if (requireValidation) { //re-validate email user.EmailToRevalidate = newEmail; _userService.UpdateUser(user); //email re-validation message _genericAttributeService.SaveAttribute(user, SystemUserAttributeNames.EmailRevalidationToken, Guid.NewGuid().ToString()); _workflowMessageService.SendUserEmailRevalidationMessage(user, _workContext.WorkingLanguage.Id); } else { user.Email = newEmail; _userService.UpdateUser(user); //update newsletter subscription (if required) if (!String.IsNullOrEmpty(oldEmail) && !oldEmail.Equals(newEmail, StringComparison.InvariantCultureIgnoreCase)) { foreach (var application in _applicationService.GetAllApplications()) { var subscriptionOld = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndApplicationId(oldEmail, application.Id); if (subscriptionOld != null) { subscriptionOld.Email = newEmail; _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscriptionOld); } } } } }
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); }
/// <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); }
/// <summary> /// Updates 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 UpdateNewsLetterSubscription(NewsLetterSubscription newsLetterSubscription, bool publishSubscriptionEvents = true) { _newsLetterSubscriptionService.UpdateNewsLetterSubscription(newsLetterSubscription, publishSubscriptionEvents); }