Esempio n. 1
0
        public ActionResult UserProfile(bool passwordIfCorrect = true)
        {
            var serialization         = new Serialization();
            var userRegistration      = new UserRegistration();
            var HashCriteria          = new Hashtable();
            var actualCriteria        = string.Empty;
            var objUserProfileDetails = new List <UserProfileEditModel>();

            HashCriteria.Add("UserID", userID);
            actualCriteria = serialization.SerializeBinary((object)HashCriteria);
            var result = userRegistration.GetUserSpecificDetails(actualCriteria);

            objUserProfileDetails = (List <UserProfileEditModel>)(serialization.DeSerializeBinary(Convert.ToString(result)));
            var UserProfileDetails = objUserProfileDetails.FirstOrDefault();

            //UserProfileDetails.ProfileImage = CheckFileExists(UserProfileDetails.ProfileImage, "ProfileImagePath", Convert.ToString(UserProfileDetails.ID), "UserProfile");
            UserProfileDetails.ProfileImage      = CheckFileExistsGender(UserProfileDetails.ProfileImage, UserProfileDetails.Gender, "ProfileImagePath", Convert.ToString(UserProfileDetails.ID), "UserProfile");
            UserProfileDetails.SubscriptionModel = new SubscriptionModel();
            var subscriptionController = new SubscriptionController();

            UserProfileDetails.SubscriptionModel.CardType            = subscriptionController.GetPaymentCardType();
            UserProfileDetails.SubscriptionModel.ExpirationYearList  = subscriptionController.GetExpirationYear();
            UserProfileDetails.SubscriptionModel.ExpirationMonthList = subscriptionController.GetExpirationMonth();
            Session["ProfileImage"] = null;
            if (!passwordIfCorrect)
            {
                ViewBag.Error = "Please enter correct password";
            }
            else
            {
                //To get the customer credit card information for this user
                string customerID = UserProfileDetails.CustomerID;
                if (customerID != null && customerID != "")
                {
                    var            customerService = new StripeCustomerService();
                    StripeCustomer stripeCustomer  = customerService.Get(customerID);
                    var            cardService     = new StripeCardService();
                    StripeCard     stripeCard      = cardService.Get(customerID, stripeCustomer.DefaultSourceId); // optional isRecipient
                    foreach (var card in UserProfileDetails.SubscriptionModel.CardType)
                    {
                        //stripeCard.Brand = UserProfileDetails.SubscriptionModel.CardType[0].Name;
                        UserProfileDetails.SubscriptionModel.CardType[0].Name = stripeCard.Brand;
                        UserProfileDetails.SubscriptionModel.CardTypeID       = Convert.ToInt32(UserProfileDetails.SubscriptionModel.CardType[0].ID);
                    }
                    if (stripeCard.AddressCity != null)
                    {
                        UserProfileDetails.SubscriptionModel.BillingAddress = stripeCard.AddressCity;
                    }
                    UserProfileDetails.SubscriptionModel.ExpirationMonth = stripeCard.ExpirationMonth;
                    UserProfileDetails.SubscriptionModel.ExpirationYear  = stripeCard.ExpirationYear;
                    UserProfileDetails.SubscriptionModel.CardTypeID      = UserProfileDetails.SubscriptionModel.CardTypeID;
                    UserProfileDetails.SubscriptionModel.CardNumber      = "********" + stripeCard.Last4;
                    UserProfileDetails.SubscriptionModel.NameOnCard      = stripeCard.Name;
                    UserProfileDetails.SubscriptionModel.BillingAddress  = stripeCard.AddressLine1;
                    UserProfileDetails.SubscriptionModel.City            = stripeCard.AddressCity;
                    if (stripeCard.AddressState != null)
                    {
                        UserProfileDetails.SubscriptionModel.State = stripeCard.AddressState;
                    }
                    if (stripeCard.AddressZip != null)
                    {
                        UserProfileDetails.SubscriptionModel.Zip = stripeCard.AddressZip;
                    }
                }
            }
            return(View(UserProfileDetails));
        }
Esempio n. 2
0
        public ActionResult UpdateUserDetails(UserProfileEditModel userProfileModel)
        {
            if (ModelState.ContainsKey("SubscriptionModel.CardNumber"))
            {
                ModelState["SubscriptionModel.CardNumber"].Errors.Clear();
            }

            var serialization          = new Serialization();
            var userRegistration       = new UserRegistration();
            var objUserProfileDetails  = new List <UserProfileEditModel>();
            var userProfileEditModel   = new UserProfileEditModel();
            var subscriptionController = new SubscriptionController();
            var subscriptionModel      = userProfileModel.SubscriptionModel; //new SubscriptionModel();
            var HashCriteria           = new Hashtable();
            var HashCriteriaPassword   = new Hashtable();
            var actualCriteria         = string.Empty;
            var actualCriteriaPassword = string.Empty;
            var passwordIfCorrect      = false;

            HashCriteria.Add("ID", userProfileModel.ID);
            HashCriteria.Add("Name", userProfileModel.Name);
            HashCriteria.Add("Address", userProfileModel.Address);
            HashCriteria.Add("City", userProfileModel.City);
            HashCriteria.Add("StateName", userProfileModel.StateName);
            HashCriteria.Add("ZipCode", userProfileModel.ZipCode);
            HashCriteria.Add("CompanyName", userProfileModel.CompanyName);
            HashCriteria.Add("LicenceNumber", userProfileModel.LicenceNumber);
            HashCriteria.Add("PhoneNumber", userProfileModel.PhoneNumber);
            HashCriteria.Add("UserID", userID);
            userProfileEditModel.ProfileImage = userProfileModel.ProfileImage;
            userProfileEditModel.PhoneNumber  = userProfileModel.PhoneNumber;
            userProfileEditModel.Email        = userProfileModel.Email;
            userProfileEditModel.CompanyName  = userProfileModel.CompanyName;

            if (subscriptionModel != null)
            {
                subscriptionModel.ExpirationYearList  = new List <ExpirationYear>();
                subscriptionModel.CardType            = new List <PaymentCardTypes>();
                subscriptionModel.ExpirationMonthList = new List <ExpirationMonth>();
                subscriptionModel.ExpirationYearList  = subscriptionController.GetExpirationYear();
                subscriptionModel.CardType            = subscriptionController.GetPaymentCardType();
                subscriptionModel.ExpirationMonthList = subscriptionController.GetExpirationMonth();
            }

            userProfileEditModel.SubscriptionModel = subscriptionModel;
            ModelState.Remove("SecurityCode");

            if (string.IsNullOrWhiteSpace(userProfileModel.CurrentPassword) && !string.IsNullOrWhiteSpace(userProfileModel.Password) && !string.IsNullOrWhiteSpace(userProfileModel.ConfirmPassword))
            {
                ModelState.AddModelError("CurrentPassword", "Please Enter valid current password");
                return(View("UserProfile", userProfileModel));
            }

            if (ModelState.IsValid)
            {
                if (SessionController.UserSession.RoleType == "Admin")
                {
                    actualCriteria = serialization.SerializeBinary((object)HashCriteria);
                    var  result        = userRegistration.UpdateUserProfile(actualCriteria);
                    long updatedUserID = Convert.ToInt64(serialization.DeSerializeBinary(Convert.ToString(result)));
                    SaveProfileImage(userProfileModel.ID);
                    TempData["UserSuccess"] = "User details has been modified successfully..!";
                    return(View("UserProfile", userProfileModel));
                }
                //Check if entered password is exists or not
                HashCriteriaPassword.Add("UserID", userProfileModel.ID);
                actualCriteriaPassword = serialization.SerializeBinary((object)HashCriteriaPassword);
                var userResult = userRegistration.GetUserSpecificDetails(actualCriteriaPassword);
                objUserProfileDetails = (List <UserProfileEditModel>)(serialization.DeSerializeBinary(Convert.ToString(userResult)));
                var  UserProfileDetails = objUserProfileDetails.FirstOrDefault();
                bool isValidPassword    = false;
                if (!string.IsNullOrWhiteSpace(userProfileModel.CurrentPassword))
                {
                    isValidPassword = CipherTool.Verify(userProfileModel.CurrentPassword, Convert.ToString(UserProfileDetails.Password));
                }

                passwordIfCorrect = true;
                if (passwordIfCorrect)
                {
                    if (isValidPassword)
                    {
                        string newPassword = CipherTool.Encrypt(Convert.ToString(userProfileModel.Password));
                        HashCriteria.Add("Password", newPassword);
                    }

                    if (!string.IsNullOrWhiteSpace(userProfileModel.CurrentPassword) && !isValidPassword)
                    {
                        ModelState.AddModelError("CurrentPassword", "Current password is not correct, Please Enter valid current password");
                        return(View("UserProfile", userProfileModel));
                    }

                    actualCriteria = serialization.SerializeBinary((object)HashCriteria);
                    var result = userRegistration.UpdateUserProfile(actualCriteria);
                    SaveProfileImage(Convert.ToInt64(userProfileModel.ID));   // user id
                    int year = 0;
                    if (userProfileModel.SubscriptionModel != null)
                    {
                        if (userProfileModel.SubscriptionModel.ExpirationYear != 0)
                        {
                            var selectedItem = subscriptionModel.ExpirationYearList.Find(p => p.ID == userProfileModel.SubscriptionModel.ExpirationYear);
                            year = Convert.ToInt32(selectedItem.Year);
                        }
                    }

                    //Update the user Credit card details
                    string customerID = Convert.ToString(SessionController.UserSession.CustomerID);
                    if (customerID != null && customerID != "" && (SessionController.UserSession.IsPaid = true))
                    {
                        try
                        {
                            var            customerService = new StripeCustomerService();
                            StripeCustomer stripeCustomer  = customerService.Get(customerID);
                            var            myCard          = new StripeCardUpdateOptions();
                            if (userProfileModel.SubscriptionModel.NameOnCard != null)
                            {
                                myCard.Name = userProfileModel.SubscriptionModel.NameOnCard;
                            }
                            myCard.ExpirationYear  = year;
                            myCard.ExpirationMonth = userProfileModel.SubscriptionModel.ExpirationMonth;
                            myCard.AddressState    = userProfileModel.SubscriptionModel.State;
                            myCard.AddressCity     = userProfileModel.SubscriptionModel.City;
                            myCard.AddressZip      = userProfileModel.SubscriptionModel.Zip;
                            myCard.AddressLine1    = userProfileModel.SubscriptionModel.BillingAddress;
                            var        cardService = new StripeCardService();
                            StripeCard stripeCard  = cardService.Update(customerID, stripeCustomer.DefaultSourceId, myCard); // optional isRecipient
                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError("", ex.Message);
                            return(View("UserProfile", userProfileModel));
                        }
                    }
                    TempData["UserSuccess"] = "User details has been modified successfully..!";
                    return(RedirectToAction("UserProfile", new
                    {
                        passwordIfCorrect = passwordIfCorrect
                    }));
                }
                else
                {
                    passwordIfCorrect = false;
                }
            }

            return(View("UserProfile", userProfileModel));
        }