public async Task <ActionResult> NewsletterSignUp(NewsletterSignUpForm signUpForm) { if (!this.ModelState.IsValid) { return(this.View(signUpForm)); } var firstName = signUpForm.FirstName.Trim().ToLowerInvariant(); signUpForm.FirstName = firstName.First().ToString().ToUpper() + firstName.Substring(1); signUpForm.Email = signUpForm.Email.ToLowerInvariant(); this.ViewBag.FormSubmitted = await Task.Run(() => this.blogService.AddUserToNewsletterSubscriberList(signUpForm)); return(this.View()); }
/// <summary> /// Adds the user to newsletter subscriber list. /// </summary> /// <param name="signUpForm">The sign up form.</param> /// <returns>NewsletterSignUpState.</returns> public NewsletterSignUpState AddUserToNewsletterSubscriberList(NewsletterSignUpForm signUpForm) { var newsletterTable = this.newsletterContext.CustomOperation(); var foundUser = (from record in newsletterTable.CreateQuery <TableNewsletterEntity>() where record.PartitionKey == ApplicationConstants.SubscriberListKey && record.RowKey == signUpForm.Email select record).FirstOrDefault(); //// If user does not exist. Create a user. if (null == foundUser) { signUpForm.CreatedDate = DateTime.UtcNow; signUpForm.LastEmailIdentifier = string.Empty; signUpForm.VerificationString = Guid.NewGuid().ToString(); signUpForm.UnsubscribeString = Guid.NewGuid().ToString(); signUpForm.IsVerified = false; var tableEntity = new TableNewsletterEntity(signUpForm); this.newsletterContext.InsertOrReplace(tableEntity); this.newsletterContext.Save(); //// Add message to queue. this.AddMessageToNewUserQueue(signUpForm.Email); return(NewsletterSignUpState.Success); } //// If user exists and is not verified, reactivate by changing verification string and date. if (!foundUser.IsVerified) { signUpForm.CreatedDate = DateTime.UtcNow; signUpForm.LastEmailIdentifier = string.Empty; signUpForm.VerificationString = Guid.NewGuid().ToString(); signUpForm.UnsubscribeString = Guid.NewGuid().ToString(); signUpForm.IsVerified = false; var tableEntity = new TableNewsletterEntity(signUpForm); this.newsletterContext.InsertOrReplace(tableEntity); this.newsletterContext.Save(); //// Add message to queue. this.AddMessageToNewUserQueue(signUpForm.Email); return(NewsletterSignUpState.Success); } //// If user exists. Do nothing. return(NewsletterSignUpState.UserExists); }