コード例 #1
0
        public ActionResult ChangeEmail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var customerService = new StripeCustomerService();
            var stripeCustomer  = customerService.Get(id);

            var model = new CustomerChangeEmailViewModel
            {
                Id       = id,
                OldEmail = stripeCustomer.Email,
                NewEmail = ""
            };

            return(View(model));
        }
コード例 #2
0
        public ActionResult ChangeEmail(CustomerChangeEmailViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (UserManager.Users.Any(u => u.Email == model.NewEmail))
            {
                ModelState.AddModelError("NewEmail", "That email is already in use. Please choose a different email other than" + model.NewEmail);
                return(View(model));
            }

            // First change the customer stripe email address
            var options = new StripeCustomerUpdateOptions
            {
                Email = model.NewEmail
            };
            var customerService = new StripeCustomerService();

            customerService.Update(model.Id, options);

            // Next change the user account email address
            var user = UserManager.Users.First(u => u.Email == model.OldEmail);

            user.Email    = model.NewEmail;
            user.UserName = model.NewEmail;
            UserManager.Update(user);

            // Finally change the Subscription entity
            var sub = db.Subscriptions.First(s => s.AdminEmail == model.OldEmail);

            sub.AdminEmail = model.NewEmail;
            db.Subscriptions.AddOrUpdate();
            db.SaveChanges();

            return(RedirectToAction("Details", new { id = model.Id }));
        }