public ActionResult Profile()
        {
            var model = new ProfileModel();
            model.NewCreditCardTypes = RegisterNewCreditCardTypes(false);
            model.NewCreditCardType = string.Empty;
            model.NewCreditCardExpireMonths = RegisterNewCreditCardExpireMonths(false);
            model.NewCreditCardExpireMonth = string.Empty;
            model.NewCreditCardExpireYears = RegisterNewCreditCardExpireYears(false);
            model.NewCreditCardExpireYear = string.Empty;

            if (User.Identity.IsAuthenticated)
            {
                var email = User.Identity.Name.Trim();
                bool isSuccess = DataBind(model, email);
            }
            else
            {
                RedirectToAction("Index", "Home");
            }

            return View(model);
        }
        public ActionResult Profile(ProfileModel model)
        {
            if (ModelState.IsValid)
            {
                bool changeProfileSucceeded = false;
                try
                {
                    var email = User.Identity.Name.Trim();
                    bool isValid = IsPasswordValid(email, model.CurrentPassword.Trim());
                    if (isValid)
                    {
                        var newPassword = model.NewPassword.Trim();
                        var confirmNewPassword = model.ConfirmNewPassword.Trim();
                        var newCreditCardType = model.NewCreditCardType.Trim();
                        var newCreditCardNumber = model.NewCreditCardNumber.Trim();
                        var newCreditCardCVV2 = model.NewCreditCardCVV2.Trim();
                        var newCreditCardExpireMonth = model.NewCreditCardExpireMonth.Trim();
                        var newCreditCardExpireYear = model.NewCreditCardExpireYear.Trim();

                        bool isSuccess = Update(email, newPassword, confirmNewPassword,
                            newCreditCardType, newCreditCardNumber, newCreditCardCVV2, newCreditCardExpireMonth, newCreditCardExpireYear);
                        if (isSuccess)
                        {
                            changeProfileSucceeded = true;
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "The current password provided is incorrect.");
                    }
                }
                catch (Exception)
                {
                    changeProfileSucceeded = false;
                }

                if (changeProfileSucceeded)
                {
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Profile update failed.");
                }
            }

            if (model.NewCreditCardTypes == null)
            {
                model.NewCreditCardTypes = RegisterNewCreditCardTypes(true);
            }

            if (model.NewCreditCardExpireMonths == null)
            {
                model.NewCreditCardExpireMonths = RegisterNewCreditCardExpireMonths(true);
            }

            if (model.NewCreditCardExpireYears == null)
            {
                model.NewCreditCardExpireYears = RegisterNewCreditCardExpireYears(true);
            }
            return View(model);
        }
        private SelectListItem[] RegisterNewCreditCardTypes(bool isValid)
        {
            var model = new ProfileModel();

            model.NewCreditCardTypes = new[]
            {
                new SelectListItem { Selected = isValid, Text = "--Select--", Value = string.Empty },
                new SelectListItem { Text = "visa", Value = "visa" },
                new SelectListItem { Text = "mastercard", Value = "mastercard" },
                new SelectListItem { Text = "discover", Value = "discover" },
                new SelectListItem { Text = "amex", Value = "amex" },
            };
            return model.NewCreditCardTypes;
        }
        private SelectListItem[] RegisterNewCreditCardExpireYears(bool isValid)
        {
            var model = new ProfileModel();

            model.NewCreditCardExpireYears = new[]
            {
                new SelectListItem { Selected = isValid, Text = "--Select--", Value = string.Empty },
                new SelectListItem { Text = "2013", Value = "2013" },
                new SelectListItem { Text = "2014", Value = "2014" },
                new SelectListItem { Text = "2015", Value = "2015" },
                new SelectListItem { Text = "2016", Value = "2016" },
                new SelectListItem { Text = "2017", Value = "2017" },
                new SelectListItem { Text = "2018", Value = "2018" },
                new SelectListItem { Text = "2019", Value = "2019" },
                new SelectListItem { Text = "2020", Value = "2020" },
                new SelectListItem { Text = "2021", Value = "2021" },
                new SelectListItem { Text = "2022", Value = "2022" },
                new SelectListItem { Text = "2023", Value = "2023" },
            };
            return model.NewCreditCardExpireYears;
        }
        private SelectListItem[] RegisterNewCreditCardExpireMonths(bool isValid)
        {
            var model = new ProfileModel();

            model.NewCreditCardExpireMonths = new[]
            {
                new SelectListItem { Selected = isValid, Text = "--Select--", Value = string.Empty },
                new SelectListItem { Text = "01", Value = "01" },
                new SelectListItem { Text = "02", Value = "02" },
                new SelectListItem { Text = "03", Value = "03" },
                new SelectListItem { Text = "04", Value = "04" },
                new SelectListItem { Text = "05", Value = "05" },
                new SelectListItem { Text = "06", Value = "06" },
                new SelectListItem { Text = "07", Value = "07" },
                new SelectListItem { Text = "08", Value = "08" },
                new SelectListItem { Text = "09", Value = "09" },
                new SelectListItem { Text = "10", Value = "10" },
                new SelectListItem { Text = "11", Value = "11" },
                new SelectListItem { Text = "12", Value = "12" },
            };
            return model.NewCreditCardExpireMonths;
        }
 private bool DataBind(ProfileModel model, string email)
 {
     bool isSuccess = false;
     model.Email = email;
     DataTable datTable = GetUser(email);
     if (datTable != null && datTable.Rows.Count > 0)
     {
         string creditCardId = string.Empty;
         if (datTable.Rows[0]["credit_card_id"] != DBNull.Value)
         {
             creditCardId = Convert.ToString(datTable.Rows[0]["credit_card_id"]);
         }
         CreditCard crdtCard = CreditCard.Get(Api, creditCardId);
         model.CurrentCreditCardNumber = crdtCard.number.Trim();
         isSuccess = true;
     }
     return isSuccess;
 }