void AddressEdit_Billing_ControlSaved(object sender, Common.Events.ControlSavedEventArgs e)
 {
     try
     {
         hccUserProfile userProfile = hccUserProfile.GetById(this.PrimaryKeyIndex);
         userProfile.BillingAddressID = int.Parse(e.PrimaryKeyIndex.ToString());
         userProfile.Save();
         chkUpdateCard.Enabled = true;
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        void SaveLedger(hccLedger ledger, hccCart CurrentCart, hccUserProfile profile)
        {
            ledger = new hccLedger
            {
                PaymentDue        = CurrentCart.PaymentDue,
                TotalAmount       = CurrentCart.TotalAmount,
                AspNetUserID      = CurrentCart.AspNetUserID.Value,
                AsscCartID        = CurrentCart.CartID,
                CreatedBy         = (Guid)Helpers.LoggedUser.ProviderUserKey,
                CreatedDate       = DateTime.Now,
                Description       = "Cart Order Payment - Purchase Number: " + CurrentCart.PurchaseNumber.ToString() + " - from re-snapshot of order.",
                TransactionTypeID = (int)Enums.LedgerTransactionType.Purchase
            };

            if (CurrentCart.IsTestOrder)
            {
                ledger.Description += " - Test Mode";
            }

            if (CurrentCart.CreditAppliedToBalance > 0)
            {
                profile.AccountBalance   = profile.AccountBalance - CurrentCart.CreditAppliedToBalance;
                ledger.CreditFromBalance = CurrentCart.CreditAppliedToBalance;
            }

            hccLedger lastLedger        = hccLedger.GetByMembershipID(profile.MembershipID, null).OrderByDescending(a => a.CreatedDate).FirstOrDefault();
            bool      isDuplicateLedger = false;

            if (lastLedger != null)
            {
                if (ledger.CreatedBy == lastLedger.CreatedBy &&
                    ledger.CreditFromBalance == lastLedger.CreditFromBalance &&
                    ledger.Description == lastLedger.Description &&
                    ledger.PaymentDue == lastLedger.PaymentDue &&
                    ledger.TransactionTypeID == lastLedger.TransactionTypeID &&
                    ledger.TotalAmount == lastLedger.TotalAmount)
                {
                    isDuplicateLedger = true;
                }
            }

            if (!isDuplicateLedger)
            {
                ledger.PostBalance = profile.AccountBalance;
                ledger.Save();
                profile.Save();
            }
        }
        public RoledUser(MembershipUser user)
        {
            StringBuilder roles = new StringBuilder();

            Roles.GetRolesForUser(user.UserName).ToList().ForEach(a => roles.Append(a));

            ProviderUserKey = user.ProviderUserKey;
            Email           = user.Email;
            IsApproved      = user.IsApproved;
            IsLockedOut     = user.IsLockedOut;
            IsOnline        = user.IsOnline;
            UserRoles       = roles.ToString();

            if (UserRoles.Contains("Customer"))
            {
                hccUserProfile profile = hccUserProfile.GetParentProfileBy((Guid)user.ProviderUserKey);

                //Create basic profile is user does not have one.
                if (profile == null)
                {
                    profile = new hccUserProfile
                    {
                        MembershipID   = (Guid)user.ProviderUserKey,
                        CreatedBy      = (Guid)Helpers.LoggedUser.ProviderUserKey,
                        CreatedDate    = DateTime.Now,
                        IsActive       = true,
                        AccountBalance = 0.00m,
                        ProfileName    = "Main"
                    };
                    profile.Save();
                }
                else
                {
                    this.FullName = profile.FullName;
                }
            }
        }
        private void ProcessNewOrder(int cartId)
        {
            //bool dupTransaction = false;
            hccCart CurrentCart = null;

            try
            {
                // TODO: Check the cart for more then one recurring item

                CurrentCart = hccCart.GetById(cartId);

                hccUserProfile profile  = hccUserProfile.GetParentProfileBy(CurrentCart.AspNetUserID.Value);
                hccAddress     billAddr = null;

                var ppName =
                    hccUserProfile.GetParentProfileBy((Guid)hccCart.GetById(cartId).AspNetUserID).ParentProfileName;
                var pName = hccUserProfile.GetParentProfileBy((Guid)hccCart.GetById(cartId).AspNetUserID).ASPUser.Email;

                //if (CurrentCart.StatusID == (int)Enums.CartStatus.Unfinalized)
                if (CurrentCart.StatusID == (int)Enums.CartStatus.Unfinalized)
                {
                    if (profile != null)
                    {
                        AuthNetConfig ANConfig = new AuthNetConfig();
                        hccUserProfilePaymentProfile activePaymentProfile = profile.ActivePaymentProfile;
                        bool isDuplicateTransaction = false;
                        bool isAuthNet = false;

                        if (ANConfig.Settings.TestMode)
                        {
                            CurrentCart.IsTestOrder = true;
                        }

                        // Check for existing account balance, calculate total balance
                        if (CurrentCart.PaymentDue > 0.00m)
                        {
                            try
                            {
                                // if total balance remains
                                CustomerInformationManager cim = new CustomerInformationManager();

                                if (activePaymentProfile != null)
                                {
                                    // do not validate, per Duncan, YouTrack HC1-339
                                    //string valProfile = cim.ValidateProfile(profile.AuthNetProfileID,
                                    //    activePaymentProfile.AuthNetPaymentProfileID, AuthorizeNet.ValidationMode.TestMode);

                                    AuthorizeNet.Order order = new AuthorizeNet.Order(profile.AuthNetProfileID,
                                                                                      activePaymentProfile.AuthNetPaymentProfileID, null);

                                    // charge CIM account with PaymentDue balance
                                    order.Amount        = CurrentCart.PaymentDue;
                                    order.InvoiceNumber = CurrentCart.PurchaseNumber.ToString();
                                    order.Description   = "Healthy Chef Creations Purchase #" +
                                                          CurrentCart.PurchaseNumber.ToString();
                                    // Add a PO number to make purchases unique as subsequent transactions with the same amount are rejected by Auth.net as duplicate
                                    // order.PONumber = "PO" + CurrentCart.PurchaseNumber.ToString();

                                    AuthorizeNet.IGatewayResponse rsp = cim.AuthorizeAndCapture(order);

                                    try
                                    {
                                        CurrentCart.AuthNetResponse = rsp.ResponseCode + "|" + rsp.Approved.ToString()
                                                                      + "|" + rsp.AuthorizationCode + "|" +
                                                                      rsp.InvoiceNumber + "|" + rsp.Message
                                                                      + "|" + rsp.TransactionID + "|" +
                                                                      rsp.Amount.ToString() + "|" + rsp.CardNumber;
                                    }
                                    catch (Exception)
                                    {
                                    }

                                    if (rsp.ResponseCode.StartsWith("1"))
                                    {
                                        CurrentCart.ModifiedBy       = (Guid)Helpers.LoggedUser.ProviderUserKey;
                                        CurrentCart.ModifiedDate     = DateTime.Now;
                                        CurrentCart.PurchaseBy       = (Guid)Helpers.LoggedUser.ProviderUserKey;
                                        CurrentCart.PurchaseDate     = DateTime.Now;
                                        CurrentCart.PaymentProfileID = activePaymentProfile.PaymentProfileID;
                                        CurrentCart.StatusID         = (int)Enums.CartStatus.Paid;

                                        isAuthNet = true;
                                    }
                                    else if (rsp.Message.Contains("E00027")) // Duplicate transaction
                                    {
                                        order = new AuthorizeNet.Order(profile.AuthNetProfileID,
                                                                       activePaymentProfile.AuthNetPaymentProfileID, null)
                                        {
                                            Amount = CurrentCart.PaymentDue - .01m,
                                            // Subtract a penny from payment to make the value distinct
                                            InvoiceNumber = CurrentCart.PurchaseNumber.ToString(),
                                            Description   =
                                                "Healthy Chef Creations Purchase #" +
                                                CurrentCart.PurchaseNumber.ToString()
                                        };

                                        // charge CIM account with PaymentDue balance
                                        rsp = cim.AuthorizeAndCapture(order);

                                        try
                                        {
                                            CurrentCart.AuthNetResponse = rsp.ResponseCode + "|" +
                                                                          rsp.Approved.ToString()
                                                                          + "|" + rsp.AuthorizationCode + "|" +
                                                                          rsp.InvoiceNumber + "|" + rsp.Message
                                                                          + "|" + rsp.TransactionID + "|" +
                                                                          rsp.Amount.ToString() + "|" + rsp.CardNumber;

                                            if (rsp.ResponseCode.StartsWith("1"))
                                            {
                                                //CurrentCart.PaymentDue = CurrentCart.PaymentDue - .01m;
                                                CurrentCart.ModifiedBy       = (Guid)Helpers.LoggedUser.ProviderUserKey;
                                                CurrentCart.ModifiedDate     = DateTime.Now;
                                                CurrentCart.PurchaseBy       = (Guid)Helpers.LoggedUser.ProviderUserKey;
                                                CurrentCart.PurchaseDate     = DateTime.Now;
                                                CurrentCart.PaymentProfileID = activePaymentProfile.PaymentProfileID;
                                                CurrentCart.StatusID         = (int)Enums.CartStatus.Paid;

                                                isAuthNet = true;
                                            }
                                            else
                                            {
                                                lblConfirmFeedback.Text += "Authorize.Net " + rsp.Message + @" (" +
                                                                           ppName + @", " + pName + @")" + @"<br />";
                                                // CurrentCart.AuthNetResponse;
                                                lblConfirmFeedback.ForeColor = System.Drawing.Color.Red;
                                            }
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    }
                                    else
                                    {
                                        lblConfirmFeedback.Text += "Authorize.Net " + rsp.Message + @" (" + ppName +
                                                                   @", " + pName + @")" + @"<br />";
                                        // CurrentCart.AuthNetResponse;
                                        lblConfirmFeedback.ForeColor = System.Drawing.Color.Red;
                                    }
                                    CurrentCart.Save();
                                }
                                else
                                {
                                    lblConfirmFeedback.Text += "No payment profile found." + @" (" + ppName + @", " +
                                                               pName + @")" + @"<br />";
                                }
                            }
                            catch (Exception ex)
                            {
                                lblConfirmFeedback.Text += "Authorize.Net " + ex.Message + @" (" + ppName + @", " +
                                                           pName + @")" + @"<br />";
                                lblConfirmFeedback.ForeColor = System.Drawing.Color.Red;
                                if (ex is InvalidOperationException)
                                {
                                    if (CurrentCart.IsTestOrder)
                                    {
                                        CurrentCart.ModifiedBy       = (Guid)Helpers.LoggedUser.ProviderUserKey;
                                        CurrentCart.ModifiedDate     = DateTime.Now;
                                        CurrentCart.PaymentProfileID = activePaymentProfile.PaymentProfileID;
                                        CurrentCart.AuthNetResponse  = ex.Message;
                                        CurrentCart.StatusID         = (int)Enums.CartStatus.Unfinalized;
                                        CurrentCart.Save();
                                    }
                                    else
                                    {
                                        BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise(ex.Message, this, ex);
                                        lblConfirmFeedback.Visible = true;
                                        lblConfirmFeedback.Text   += "Authorize.Net " + ex.Message + @" (" + ppName +
                                                                     @", " + pName + @")" + @"<br />";
                                        lblConfirmFeedback.ForeColor = System.Drawing.Color.Red;
                                    }
                                }
                                else
                                {
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            // no balance left to pay on order, set as paid
                            CurrentCart.AuthNetResponse = "Paid with account balance.";
                            CurrentCart.ModifiedBy      = (Guid)Helpers.LoggedUser.ProviderUserKey;
                            CurrentCart.ModifiedDate    = DateTime.Now;
                            CurrentCart.PurchaseBy      = (Guid)Helpers.LoggedUser.ProviderUserKey;
                            CurrentCart.PurchaseDate    = DateTime.Now;
                            CurrentCart.StatusID        = (int)Enums.CartStatus.Paid;
                            CurrentCart.Save();
                        }

                        if ((Enums.CartStatus)CurrentCart.StatusID == Enums.CartStatus.Paid)
                        //&& !isDuplicateTransaction
                        {
                            hccLedger ledger = new hccLedger
                            {
                                //PaymentDue = dupTransaction ? CurrentCart.PaymentDue : CurrentCart.PaymentDue - .01m,
                                //TotalAmount = dupTransaction ? CurrentCart.TotalAmount : CurrentCart.TotalAmount - .01m,
                                PaymentDue   = CurrentCart.PaymentDue,
                                TotalAmount  = CurrentCart.TotalAmount,
                                AspNetUserID = CurrentCart.AspNetUserID.Value,
                                AsscCartID   = CurrentCart.CartID,
                                CreatedBy    = (Guid)Helpers.LoggedUser.ProviderUserKey,
                                CreatedDate  = DateTime.Now,
                                Description  =
                                    "Cart Order Payment - Purchase Number: " + CurrentCart.PurchaseNumber.ToString(),
                                TransactionTypeID = (int)Enums.LedgerTransactionType.Purchase
                            };

                            if (CurrentCart.IsTestOrder)
                            {
                                ledger.Description += " - Test Mode";
                            }

                            if (CurrentCart.CreditAppliedToBalance > 0)
                            {
                                profile.AccountBalance   = profile.AccountBalance - CurrentCart.CreditAppliedToBalance;
                                ledger.CreditFromBalance = CurrentCart.CreditAppliedToBalance;
                            }

                            hccLedger lastLedger =
                                hccLedger.GetByMembershipID(profile.MembershipID, null)
                                .OrderByDescending(a => a.CreatedDate)
                                .FirstOrDefault();
                            bool isDuplicateLedger = false;

                            if (lastLedger != null)
                            {
                                if (ledger.CreatedBy == lastLedger.CreatedBy &&
                                    ledger.CreditFromBalance == lastLedger.CreditFromBalance &&
                                    ledger.Description == lastLedger.Description &&
                                    ledger.PaymentDue == lastLedger.PaymentDue &&
                                    ledger.TransactionTypeID == lastLedger.TransactionTypeID &&
                                    ledger.TotalAmount == lastLedger.TotalAmount)
                                {
                                    isDuplicateLedger = true;
                                }
                            }

                            if (!isDuplicateLedger)
                            {
                                ledger.PostBalance = profile.AccountBalance;
                                ledger.Save();
                                profile.Save();

                                // create snapshot here
                                hccCartSnapshot snap = new hccCartSnapshot
                                {
                                    CartId                  = cartId,
                                    MembershipId            = profile.MembershipID,
                                    LedgerId                = ledger.LedgerID,
                                    AccountBalance          = profile.AccountBalance,
                                    AuthNetProfileId        = profile.AuthNetProfileID,
                                    CreatedBy               = (Guid)Helpers.LoggedUser.ProviderUserKey,
                                    CreatedDate             = DateTime.Now,
                                    DefaultCouponId         = profile.DefaultCouponId,
                                    Email                   = profile.ASPUser.Email,
                                    FirstName               = profile.FirstName,
                                    LastName                = profile.LastName,
                                    ProfileName             = profile.ProfileName,
                                    AuthNetPaymentProfileId =
                                        (isAuthNet == true ? activePaymentProfile.AuthNetPaymentProfileID : string.Empty),
                                    CardTypeId = (isAuthNet == true ? activePaymentProfile.CardTypeID : 0),
                                    CCLast4    = (isAuthNet == true ? activePaymentProfile.CCLast4 : string.Empty),
                                    ExpMon     = (isAuthNet == true ? activePaymentProfile.ExpMon : 0),
                                    ExpYear    = (isAuthNet == true ? activePaymentProfile.ExpYear : 0),
                                    NameOnCard = (isAuthNet == true ? activePaymentProfile.NameOnCard : string.Empty)
                                };
                                snap.Save();

                                hccUserProfile parentProfile =
                                    hccUserProfile.GetParentProfileBy(CurrentCart.AspNetUserID.Value);
                                if (parentProfile.BillingAddressID.HasValue)
                                {
                                    billAddr = hccAddress.GetById(parentProfile.BillingAddressID.Value);
                                }

                                hccAddress snapBillAddr = new hccAddress
                                {
                                    Address1              = billAddr.Address1,
                                    Address2              = billAddr.Address2,
                                    AddressTypeID         = (int)Enums.AddressType.BillingSnap,
                                    City                  = billAddr.City,
                                    Country               = billAddr.Country,
                                    DefaultShippingTypeID = billAddr.DefaultShippingTypeID,
                                    FirstName             = billAddr.FirstName,
                                    IsBusiness            = billAddr.IsBusiness,
                                    LastName              = billAddr.LastName,
                                    Phone                 = billAddr.Phone,
                                    PostalCode            = billAddr.PostalCode,
                                    State                 = billAddr.State,
                                    ProfileName           = parentProfile.ProfileName
                                };
                                snapBillAddr.Save();

                                // copy and replace of all addresses for snapshot
                                List <hccCartItem> cartItems = hccCartItem.GetBy(CurrentCart.CartID);

                                cartItems.ToList().ForEach(delegate(hccCartItem ci)
                                {
                                    hccAddress shipAddr = null;
                                    if (ci.UserProfile.ShippingAddressID.HasValue)
                                    {
                                        shipAddr = hccAddress.GetById(ci.UserProfile.ShippingAddressID.Value);
                                    }

                                    if (shipAddr != null)
                                    {
                                        hccAddress snapShipAddr = new hccAddress
                                        {
                                            Address1              = shipAddr.Address1,
                                            Address2              = shipAddr.Address2,
                                            AddressTypeID         = (int)Enums.AddressType.ShippingSnap,
                                            City                  = shipAddr.City,
                                            Country               = shipAddr.Country,
                                            DefaultShippingTypeID = shipAddr.DefaultShippingTypeID,
                                            FirstName             = shipAddr.FirstName,
                                            IsBusiness            = shipAddr.IsBusiness,
                                            LastName              = shipAddr.LastName,
                                            Phone                 = shipAddr.Phone,
                                            PostalCode            = shipAddr.PostalCode,
                                            State                 = shipAddr.State,
                                            ProfileName           = ci.UserProfile.ProfileName
                                        };
                                        snapShipAddr.Save();
                                        ci.SnapShipAddrId = snapShipAddr.AddressID;
                                    }

                                    ci.SnapBillAddrId = snapBillAddr.AddressID;
                                    ci.Save();
                                });


                                try
                                {
                                    Email.EmailController ec = new Email.EmailController();
                                    ec.SendMail_OrderConfirmationMerchant(profile.FirstName + " " + profile.LastName,
                                                                          CurrentCart.ToHtml(), cartId);
                                    ec.SendMail_OrderConfirmationCustomer(profile.ASPUser.Email,
                                                                          profile.FirstName + " " + profile.LastName, CurrentCart.ToHtml());
                                }
                                catch (Exception ex)
                                {
                                    BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise("Send Mail Failed", this, ex);
                                } //throw; }

                                //if (IsForPublic)
                                //{
                                //    Response.Redirect(string.Format("~/cart/order-confirmation.aspx?pn={0}&tl={1}&tx={2}&ts={3}&ct={4}&st={5}&cy={6}",
                                //        CurrentCart.PurchaseNumber, CurrentCart.TotalAmount, CurrentCart.TaxableAmount, CurrentCart.ShippingAmount,
                                //        billAddr.City, billAddr.State, billAddr.Country), false);
                                //}
                                //else
                                //{
                                //    CurrentCart = hccCart.GetCurrentCart(profile.ASPUser);
                                //    CurrentCartId = CurrentCart.CartID;

                                //    pnlCartDisplay.Visible = true;
                                //    pnlConfirm.Visible = false;

                                //    Clear();
                                //    Bind();
                                //}
                                //OnCartSaved(new CartEventArgs(CurrentCartId));
                            }
                        }
                        //else
                        //{
                        //    BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise("Duplicate transaction attempted: " + CurrentCart.PurchaseNumber.ToString(), this, new Exception("Duplicate transaction attempted by:" + Helpers.LoggedUser.UserName));
                        //}
                    }
                    else
                    {
                        Response.Redirect("~/login.aspx", true);
                    }
                }
                //else
                //{
                //if (IsForPublic)
                //{
                //    //Response.Redirect("~/cart/order-confirmation.aspx?cid=" + CurrentCartId.ToString(), false);
                //    Response.Redirect(string.Format("~/cart/order-confirmation.aspx?pn={0}&tl={1}&tx={2}&ts={3}&ct={4}&st={5}&cy={6}",
                //                    CurrentCart.PurchaseNumber, CurrentCart.TotalAmount, CurrentCart.TaxableAmount, CurrentCart.ShippingAmount,
                //                    billAddr.City, billAddr.State, billAddr.Country), false);
                //}
                //else
                //{
                //    CurrentCart = hccCart.GetCurrentCart(profile.ASPUser);
                //    CurrentCartId = CurrentCart.CartID;

                //    pnlCartDisplay.Visible = true;
                //    pnlConfirm.Visible = false;

                //    Clear();
                //    Bind();

                //    OnCartSaved(new CartEventArgs(CurrentCartId));
                //}
                //}
            }
            catch (Exception ex)
            {
                BayshoreSolutions.WebModules.WebModulesAuditEvent.Raise(ex.Data + " " + ex.InnerException, this,
                                                                        new Exception("Recurring order error in method ProcessNewOrder: " + Helpers.LoggedUser.UserName));
            }
        }
Пример #5
0
        protected override void LoadForm()
        {
            try
            {
                BindcblRoles();
                //BindrblDeliveryTypes();
                BindddlCoupons();

                //form fields
                if (CurrentAspNetId != null)
                {
                    divPassword.Visible = true;

                    MembershipUser user = Membership.GetUser(CurrentAspNetId);

                    chkIsLockedOut.Checked = user.IsLockedOut;
                    chkIsActive.Checked    = user.IsApproved;

                    if ((Guid)user.ProviderUserKey == (Guid)Helpers.LoggedUser.ProviderUserKey)
                    {
                        chkIsLockedOut.Enabled = false;
                    }

                    txtEmail.Text = user.Email;

                    string[] userRoles = Roles.GetRolesForUser(user.UserName);

                    foreach (string role in userRoles)
                    {
                        ListItem roleItem = cblRoles.Items.FindByValue(role);

                        if (roleItem != null)
                        {
                            roleItem.Selected = true;
                        }
                    }

                    if (userRoles.ToList().Count(a => a == "Customer") > 0)
                    {
                        DisplayProfileTabs(true);
                    }
                    else
                    {
                        DisplayProfileTabs(false);
                    }

                    PasswordReset1.CurrentAspNetId = CurrentAspNetId;

                    CurrentUserProfile = hccUserProfile.GetParentProfileBy((Guid)user.ProviderUserKey);

                    if (CurrentUserProfile == null)
                    {
                        hccUserProfile newProfile = new hccUserProfile
                        {
                            MembershipID   = (Guid)user.ProviderUserKey,
                            CreatedBy      = (Guid)Helpers.LoggedUser.ProviderUserKey,
                            CreatedDate    = DateTime.Now,
                            ProfileName    = string.Empty,
                            AccountBalance = 0.00m,
                            IsActive       = true
                        };

                        newProfile.Save();
                        CurrentUserID.Value  = newProfile.MembershipID.ToString();
                        CurrentUserProfile   = newProfile;
                        this.PrimaryKeyIndex = newProfile.UserProfileID;
                    }


                    if (CurrentUserProfile != null)
                    {
                        txtProfileName.Text = CurrentUserProfile.ProfileName;
                        txtFirstName.Text   = CurrentUserProfile.FirstName;
                        txtLastName.Text    = CurrentUserProfile.LastName;

                        // Canyon Ranch
                        if (CurrentUserProfile.CanyonRanchCustomer != null)
                        {
                            cbCanyonRanchCustomer.Checked = CurrentUserProfile.CanyonRanchCustomer.Value;
                        }

                        if (CurrentUserProfile.DefaultCouponId.HasValue)
                        {
                            ddlCoupons.SelectedIndex = ddlCoupons.Items.IndexOf(
                                ddlCoupons.Items.FindByValue(CurrentUserProfile.DefaultCouponId.ToString()));
                        }

                        //billing info
                        BillingInfoEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                        BillingInfoEdit1.Bind();

                        //shipping address
                        if (CurrentUserProfile.ShippingAddressID.HasValue)
                        {
                            AddressEdit_Shipping1.PrimaryKeyIndex = CurrentUserProfile.ShippingAddressID.Value;
                            AddressEdit_Shipping1.Bind();
                        }

                        //preferences
                        ProfilePrefsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                        ProfilePrefsEdit1.Bind();

                        //allergens
                        ProfileAllgsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                        ProfileAllgsEdit1.Bind();

                        //subprofiles
                        BindgvwSubProfiles();
                        SubProfileEdit1.CurrentParentAspNetId  = CurrentAspNetId;
                        SubProfileEdit1.CurrentParentProfileId = CurrentUserProfile.UserProfileID;

                        //order history
                        BindHistory(); //0);

                        // recurring
                        BindRecurring();

                        //ledger
                        BindLedger();

                        //notes
                        ProfileNotesEdit_Billing.CurrentUserProfileId = CurrentUserProfile.UserProfileID;
                        ProfileNotesEdit_Billing.Bind();
                        ProfileNotesEdit_General.CurrentUserProfileId = CurrentUserProfile.UserProfileID;
                        ProfileNotesEdit_General.Bind();
                        ProfileNotesEdit_Shipping.CurrentUserProfileId = CurrentUserProfile.UserProfileID;
                        ProfileNotesEdit_Shipping.Bind();

                        //current cart
                        ProfileCartEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                        ProfileCartEdit1.Bind();
                    }
                }
                else
                {
                    cblRoles.Items.FindByText("Customer").Selected = true;
                    DisplayProfileTabs(true);

                    liBilling.Visible      = false;
                    liShipping.Visible     = false;
                    liPrefs.Visible        = false;
                    liAllergens.Visible    = false;
                    liSubProfiles.Visible  = false;
                    liNotes.Visible        = false;
                    liTransactions.Visible = false;
                    liPurchases.Visible    = false;
                    liCart.Visible         = false;

                    tabs2.Visible  = false;
                    tabs3.Visible  = false;
                    tabs4.Visible  = false;
                    tabs5.Visible  = false;
                    tabs6.Visible  = false;
                    tabs8.Visible  = false;
                    tabs10.Visible = false;
                    tabs7.Visible  = false;
                    tabs9.Visible  = false;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #6
0
        protected override void SaveForm()
        {
            try
            {
                MembershipUser user = null;

                if (CurrentAspNetId != null)
                {
                    user = Membership.GetUser(CurrentAspNetId);
                }
                else
                {
                    try
                    {
                        user = Membership.GetUser(Membership.GetUserNameByEmail(txtEmail.Text.Trim()));
                    }
                    catch (Exception) { }
                }

                if (user == null) // create new profile
                {
                    // create membership user

                    //formulate username
                    string email    = txtEmail.Text.Trim();
                    string userName = email.Split('@')[0] + DateTime.Now.ToString("yyyyMMddHHmmtt");
                    string password = OrderNumberGenerator.GenerateOrderNumber("?#?#?#?#");

                    MembershipCreateStatus createResult;
                    MembershipUser         newUser = Membership.CreateUser(userName, password, email, null, null, true, out createResult);

                    List <ListItem> selRoles = cblRoles.Items.OfType <ListItem>().Where(a => a.Selected).ToList();
                    selRoles.ForEach(delegate(ListItem item) { Roles.AddUserToRole(userName, item.Value); });

                    if (createResult == MembershipCreateStatus.Success)
                    {
                        CurrentAspNetId = (Guid)newUser.ProviderUserKey;

                        Email.EmailController ec = new Email.EmailController();
                        ec.SendMail_NewUserConfirmation(email, password);

                        if (selRoles.Where(a => a.Text.Contains("Customer")).Count() > 0)
                        {
                            hccUserProfile newProfile = new hccUserProfile
                            {
                                MembershipID = (Guid)newUser.ProviderUserKey,
                                CreatedBy    = (Guid)Helpers.LoggedUser.ProviderUserKey,
                                CreatedDate  = DateTime.Now,
                                ProfileName  = txtProfileName.Text.Trim(),
                                FirstName    = txtFirstName.Text.Trim(),
                                LastName     = txtLastName.Text.Trim(),
                                IsActive     = true
                            };

                            if (ddlCoupons.SelectedIndex > 0)
                            {
                                newProfile.DefaultCouponId = int.Parse(ddlCoupons.SelectedValue);
                            }
                            else
                            {
                                newProfile.DefaultCouponId = null;
                            }

                            newProfile.Save();
                            CurrentUserID.Value  = newProfile.MembershipID.ToString();
                            this.PrimaryKeyIndex = newProfile.UserProfileID;
                            Response.Redirect("~/WebModules/ShoppingCart/Admin/AccountManager.aspx?UserID=" + newProfile.MembershipID.ToString(), false);
                        }

                        liBilling.Visible      = true;
                        liShipping.Visible     = true;
                        liPrefs.Visible        = true;
                        liAllergens.Visible    = true;
                        liSubProfiles.Visible  = true;
                        liNotes.Visible        = true;
                        liTransactions.Visible = true;
                        liPurchases.Visible    = true;
                        liCart.Visible         = true;

                        tabs2.Visible  = true;
                        tabs3.Visible  = true;
                        tabs4.Visible  = true;
                        tabs5.Visible  = true;
                        tabs6.Visible  = true;
                        tabs8.Visible  = true;
                        tabs10.Visible = true;
                        tabs7.Visible  = true;
                        tabs9.Visible  = true;

                        LoadForm();

                        OnSaved(new ControlSavedEventArgs(newUser.ProviderUserKey));
                    }
                    else
                    {
                        cstValProfile0.Enabled      = true;
                        cstValProfile0.ErrorMessage = Helpers.CreateUserStatusMessage(createResult);
                        cstValProfile0.Validate();
                        Page.Validate();
                    }
                }
                else // edit existing profile
                {
                    if (user.Email != txtEmail.Text.Trim()) // update userprofile and aspmembership user
                    {
                        user.Email = txtEmail.Text.Trim();
                        Membership.UpdateUser(user);
                    }

                    if (chkIsLockedOut.Checked)
                    {
                        Helpers.LockUser(user);
                    }
                    else
                    {
                        if (user.IsLockedOut)
                        {
                            user.UnlockUser();
                        }

                        if (!user.IsApproved)
                        {
                            user.IsApproved = true;
                            Membership.UpdateUser(user);
                        }
                    }


                    List <ListItem> selRoles = cblRoles.Items.OfType <ListItem>().Where(a => a.Selected).ToList();
                    if (Roles.IsUserInRole(Helpers.LoggedUser.UserName, "Administrators"))
                    {
                        Roles.GetAllRoles().ToList().ForEach(delegate(string roleName)
                        {
                            if (Roles.IsUserInRole(user.UserName, roleName))
                            {
                                Roles.RemoveUserFromRole(user.UserName, roleName);
                            }
                        });

                        selRoles.ForEach(delegate(ListItem item)
                        {
                            Roles.AddUserToRole(user.UserName, item.Value);
                        });
                    }

                    hccUserProfile editProfile = hccUserProfile.GetParentProfileBy((Guid)user.ProviderUserKey);

                    if (editProfile == null && selRoles.Where(a => a.Text.Contains("Customer")).Count() > 0)
                    {
                        editProfile = new hccUserProfile
                        {
                            MembershipID        = (Guid)user.ProviderUserKey,
                            CreatedBy           = (Guid)Helpers.LoggedUser.ProviderUserKey,
                            CreatedDate         = DateTime.Now,
                            ProfileName         = txtProfileName.Text.Trim(),
                            FirstName           = txtFirstName.Text.Trim(),
                            LastName            = txtLastName.Text.Trim(),
                            CanyonRanchCustomer = cbCanyonRanchCustomer.Checked
                        };

                        editProfile.Save();
                        this.PrimaryKeyIndex = editProfile.UserProfileID;

                        OnSaved(new ControlSavedEventArgs(editProfile.UserProfileID));
                    }

                    if (editProfile != null)
                    {
                        editProfile.ProfileName = txtProfileName.Text.Trim();
                        editProfile.FirstName   = txtFirstName.Text.Trim();
                        editProfile.LastName    = txtLastName.Text.Trim();

                        editProfile.CanyonRanchCustomer = cbCanyonRanchCustomer.Checked;

                        if (ddlCoupons.SelectedIndex > 0)
                        {
                            editProfile.DefaultCouponId = int.Parse(ddlCoupons.SelectedValue);
                        }
                        else
                        {
                            editProfile.DefaultCouponId = null;
                        }

                        editProfile.Save();

                        if (!ProfilePrefsEdit1.ShowSave)
                        {
                            ProfilePrefsEdit1.Save();
                        }

                        if (!ProfileAllgsEdit1.ShowSave)
                        {
                            ProfileAllgsEdit1.Save();
                        }

                        ProfileCartEdit1.Bind();

                        OnSaved(new ControlSavedEventArgs(editProfile.UserProfileID));
                    }
                    OnSaved(new ControlSavedEventArgs(editProfile.UserProfileID));
                }
            }
            catch (ProviderException pex)
            {
                lblFeedback.Text = pex.Message;
            }
            catch
            {
                throw;
            }
        }
Пример #7
0
        protected override void SaveForm()
        {
            hccUserProfile userProfile = hccUserProfile.GetById(CurrentUserProfileID);
            Address        billAddr    = null;

            if (userProfile != null)
            {
                //Save CardInfo
                if (pnlCardInfo.Visible)
                {
                    CurrentCardInfo.NameOnCard   = txtNameOnCard.Text.Trim();
                    CurrentCardInfo.CardNumber   = txtCCNumber.Text.Trim();
                    CurrentCardInfo.CardType     = ValidateCardNumber(txtCCNumber.Text.Trim());
                    CurrentCardInfo.ExpMonth     = int.Parse(ddlExpMonth.SelectedValue);
                    CurrentCardInfo.ExpYear      = int.Parse(ddlExpYear.SelectedValue);
                    CurrentCardInfo.SecurityCode = txtCCAuthCode.Text.Trim();
                }

                if (userProfile.BillingAddressID.HasValue)
                {
                    billAddr = hccAddress.GetById(userProfile.BillingAddressID.Value).ToAuthNetAddress();
                }

                if (CurrentCardInfo.HasValues && billAddr != null)
                {
                    try
                    {
                        //send card to Auth.net for Auth.net profile
                        CustomerInformationManager cim = new CustomerInformationManager();
                        Customer cust         = null;
                        string   autnetResult = string.Empty;

                        if (!string.IsNullOrWhiteSpace(userProfile.AuthNetProfileID))
                        {
                            cust = cim.GetCustomer(userProfile.AuthNetProfileID);
                        }

                        //Will Martinez - Commented out on 7/30/2013.
                        //This code scans all existing Profiles generated to check for duplicated email addresses, however the site registration prevents that
                        //commented out since this process had a significant performance effect on the site.
                        //if (cust == null)
                        //    cust = cim.GetCustomerByEmail(userProfile.ASPUser.Email);

                        if (cust == null)
                        {
                            cust = cim.CreateCustomer(userProfile.ASPUser.Email, userProfile.ASPUser.UserName);
                        }

                        // had to add it back in, unable to create records with duplicate email addresses caused by IT desynching data.
                        // this should only be called infrequently since we try to create the account first.
                        if (cust.ProfileID == null)
                        {
                            cust = cim.GetCustomerByEmail(userProfile.ASPUser.Email, out autnetResult);
                        }
                        if (cust != null)
                        {
                            if (userProfile.AuthNetProfileID != cust.ProfileID)
                            {
                                userProfile.AuthNetProfileID = cust.ProfileID;
                                userProfile.Save();
                            }

                            List <PaymentProfile> payProfiles = cust.PaymentProfiles.ToList();

                            if (payProfiles.Count > 0)
                            {
                                payProfiles.ForEach(a => cim.DeletePaymentProfile(userProfile.AuthNetProfileID, a.ProfileID));
                            }

                            // create new payment profile
                            autnetResult = cim.AddCreditCard(cust, CurrentCardInfo.CardNumber, CurrentCardInfo.ExpMonth,
                                                             CurrentCardInfo.ExpYear, CurrentCardInfo.SecurityCode, billAddr);

                            if (!string.IsNullOrWhiteSpace(autnetResult))
                            {
                                // Validate card profile
                                validateCustomerPaymentProfileResponse valProfile = cim.ValidateProfile(userProfile.AuthNetProfileID,
                                                                                                        autnetResult, AuthorizeNet.ValidationMode.TestMode);

                                if (valProfile.messages.resultCode == messageTypeEnum.Ok)
                                {
                                    hccUserProfilePaymentProfile activePaymentProfile = null;
                                    activePaymentProfile = userProfile.ActivePaymentProfile;

                                    if (userProfile.ActivePaymentProfile == null)
                                    {
                                        activePaymentProfile = new hccUserProfilePaymentProfile();
                                    }

                                    activePaymentProfile.CardTypeID    = (int)CurrentCardInfo.CardType;
                                    activePaymentProfile.CCLast4       = CurrentCardInfo.CardNumber.Substring(CurrentCardInfo.CardNumber.Length - 4, 4);
                                    activePaymentProfile.ExpMon        = CurrentCardInfo.ExpMonth;
                                    activePaymentProfile.ExpYear       = CurrentCardInfo.ExpYear;
                                    activePaymentProfile.NameOnCard    = CurrentCardInfo.NameOnCard;
                                    activePaymentProfile.UserProfileID = userProfile.UserProfileID;
                                    activePaymentProfile.IsActive      = true;

                                    activePaymentProfile.AuthNetPaymentProfileID = autnetResult;
                                    activePaymentProfile.Save();
                                    this.PrimaryKeyIndex = activePaymentProfile.PaymentProfileID;

                                    OnSaved(new ControlSavedEventArgs(this.PrimaryKeyIndex));
                                    lblFeedback.Text = "Payment Profile has been created and validated.";
                                }
                                else
                                {
                                    lblFeedback.Text = "Payment Profile has been created, but validation failed.";
                                }
                            }
                            else
                            {
                                lblFeedback.Text = "Authorize.Net response is empty.";
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(autnetResult))
                            {
                                lblErrorOnAuth.Text = autnetResult;
                            }
                            OnCardInfoSaveFailed(new CardInfoSaveFailedEventArgs(new Exception(autnetResult)));
                        }
                    }
                    catch { throw; }
                }
            }
        }
        protected override void LoadForm()
        {
            try
            {
                MembershipUser user = Helpers.LoggedUser;

                //form fields
                if (user != null)
                {
                    CurrentUserProfile = hccUserProfile.GetParentProfileBy((Guid)user.ProviderUserKey);

                    if (Roles.IsUserInRole("Customer"))
                    {
                        if (CurrentUserProfile == null)
                        {
                            CurrentUserProfile = new hccUserProfile
                            {
                                AccountBalance = 0.0m,
                                CreatedBy      = (Guid)user.ProviderUserKey,
                                CreatedDate    = DateTime.Now,
                                IsActive       = true,
                                MembershipID   = (Guid)user.ProviderUserKey,
                                ModifiedBy     = (Guid)user.ProviderUserKey,
                                ModifiedDate   = DateTime.Now
                            };

                            CurrentUserProfile.Save();
                        }

                        if (CurrentUserProfile != null)
                        {
                            this.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;

                            //Basic Info
                            BasicEdit1.PrimaryKeyIndex = this.PrimaryKeyIndex;
                            BasicEdit1.Bind();

                            //shipping address
                            if (CurrentUserProfile.ShippingAddressID.HasValue)
                            {
                                AddressEdit_Shipping1.PrimaryKeyIndex = CurrentUserProfile.ShippingAddressID.Value;
                                AddressEdit_Shipping1.Bind();
                            }

                            ProfileNotesEdit_Shipping.CurrentUserProfileId = CurrentUserProfile.UserProfileID;
                            ProfileNotesEdit_Shipping.Bind();

                            //billing address
                            BillingInfoEdit1.PrimaryKeyIndex         = CurrentUserProfile.UserProfileID;
                            BillingInfoEdit1.CurrentBillingAddressID = CurrentUserProfile.BillingAddressID;
                            BillingInfoEdit1.Bind();

                            ProfileNotesEdit_Billing.CurrentUserProfileId = CurrentUserProfile.UserProfileID;
                            ProfileNotesEdit_Billing.Bind();

                            ProfilePrefsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                            ProfilePrefsEdit1.Bind();

                            ProfileAllgsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                            ProfileAllgsEdit1.Bind();

                            //subprofiles
                            BindgvwSubProfiles();
                            SubProfileEdit1.CurrentParentAspNetId  = (Guid)user.ProviderUserKey;
                            SubProfileEdit1.CurrentParentProfileId = CurrentUserProfile.UserProfileID;

                            //order history
                            PurchaseHistory1.CurrentAspNetId = (Guid)user.ProviderUserKey;
                            PurchaseHistory1.Bind();

                            //Recurring Orders
                            UserProfileRecurringOrders.CurrentAspNetId = (Guid)user.ProviderUserKey;
                            UserProfileRecurringOrders.Bind();
                        }
                    }
                    else
                    {
                        //This Account exists but doesn't have the Customer Role
                        //pnl_js_noncustomer.Visible = true;
                        li_link_01.Visible = false;
                        panel1.Visible     = false;
                        li_link_02.Visible = false;
                        panel2.Visible     = false;
                        li_link_03.Visible = false;
                        panel3.Visible     = false;
                        li_link_04.Visible = false;
                        panel4.Visible     = false;
                        li_link_05.Visible = false;
                        panel5.Visible     = false;
                        li_link_06.Visible = false;
                        panel6.Visible     = false;
                        li_link_07.Visible = false;
                        panel7.Visible     = false;
                        li_link_09.Visible = false;
                        panel9.Visible     = false;

                        if (CurrentUserProfile != null)
                        {
                            CurrentUserProfile.Activation(false);
                        }
                    }
                }
                else
                {
                    FormsAuthentication.RedirectToLoginPage();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected override void SaveForm()
        {
            try
            {
                hccLedger ledger = new hccLedger
                {
                    AspNetUserID      = CurrentAspNetUserId,
                    CreatedBy         = (Guid)Helpers.LoggedUser.ProviderUserKey,
                    CreatedDate       = DateTime.Now,
                    Description       = txtXactDesc.Text.Trim(),
                    TransactionTypeID = int.Parse(ddlXactTypes.SelectedValue)
                };

                if (ledger.TransactionType == Enums.LedgerTransactionType.RedeemGiftCertificate)
                {
                    hccCartItem gcCartItem   = hccCartItem.GetGiftBy(txtXactGCRedeem.Text);
                    bool        updateLedger = false;

                    if (gcCartItem != null)
                    {
                        gcCartItem.Gift_RedeemedBy   = CurrentAspNetUserId;
                        gcCartItem.Gift_RedeemedDate = DateTime.Now;
                        gcCartItem.Save();
                        updateLedger = true;
                    }
                    else
                    {
                        ImportedGiftCert cert = ImportedGiftCert.GetBy(txtXactGCRedeem.Text);
                        if (cert != null)
                        {
                            cert.used_by   = gcCartItem.UserProfileID;
                            cert.date_used = DateTime.Now.ToString();
                            cert.is_used   = "Y";
                            cert.Save();
                            updateLedger = true;
                        }
                    }

                    if (updateLedger)
                    {
                        ledger.TotalAmount    = gcCartItem.ItemPrice;
                        ledger.GiftRedeemCode = gcCartItem.Gift_RedeemCode;
                        ledger.Description    = "Gift Certificate Redemption: " + ledger.GiftRedeemCode;
                    }
                    else
                    {
                        ledger = null;
                    }
                }
                else
                {
                    ledger.TotalAmount = decimal.Parse(txtXactAmount.Text.Trim());
                }

                hccUserProfile profile = hccUserProfile.GetParentProfileBy(CurrentAspNetUserId);

                if (profile != null)
                {
                    // check against last entry for duplicate
                    hccLedger lastEntry        = hccLedger.GetByMembershipID(profile.MembershipID, null).OrderByDescending(a => a.CreatedDate).FirstOrDefault();
                    bool      isDuplicateEntry = false;

                    if (ledger != null)
                    {
                        if (lastEntry != null &&
                            ledger.CreatedBy == lastEntry.CreatedBy &&
                            ledger.CreditFromBalance == lastEntry.CreditFromBalance &&
                            ledger.Description == lastEntry.Description &&
                            ledger.PaymentDue == lastEntry.PaymentDue &&
                            ledger.TransactionTypeID == lastEntry.TransactionTypeID &&
                            ledger.TotalAmount == lastEntry.TotalAmount)
                        {
                            isDuplicateEntry = true;
                        }

                        if (!isDuplicateEntry)
                        {
                            switch (ledger.TransactionType)
                            {
                            case Enums.LedgerTransactionType.HCCAccountCredit:
                            case Enums.LedgerTransactionType.RedeemGiftCertificate:
                                profile.AccountBalance = profile.AccountBalance + ledger.TotalAmount;
                                break;

                            case Enums.LedgerTransactionType.HCCAccountDebit:
                                profile.AccountBalance = profile.AccountBalance - ledger.TotalAmount;
                                break;

                            case Enums.LedgerTransactionType.Purchase:
                            case Enums.LedgerTransactionType.Return:
                                ledger.PaymentDue = ledger.TotalAmount;
                                break;

                            default: break;
                            }

                            ledger.PostBalance = profile.AccountBalance;
                            ledger.Save();
                            profile.Save();

                            this.Bind();
                            OnSaved(new ControlSavedEventArgs(CurrentAspNetUserId));

                            txtXactAmount.Text   = string.Empty;
                            txtXactDesc.Text     = string.Empty;
                            txtXactGCRedeem.Text = string.Empty;
                            ddlXactTypes.ClearSelection();
                        }
                        else
                        {
                            lblXactFeedback.Text = "This appears to be a duplicate transaction. If it is not a duplicate, please provide a comment to differentiate this transaction from the last.";
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            try
            {
                Page.Validate("NewUserGroup");

                if (Page.IsValid)
                {
                    //Fill cart from anonymous user
                    MembershipUser user = Membership.GetUser();

                    if (user != null)
                    {
                        CurrentCart = hccCart.GetCurrentCart(user);
                    }
                    else
                    {
                        CurrentCart = hccCart.GetCurrentCart();
                    }

                    UserRegistration_Module userRegistrationModule = null;
                    WebpageInfo             confirmPage            = null;

                    if (null != this.WebModuleInfo)
                    {
                        UserRegistration_Module.Get(this.WebModuleInfo.Id);
                    }

                    //formulate username
                    if (CurrentAspNetId != null)
                    {
                        user = Membership.GetUser(CurrentAspNetId);
                    }

                    string email    = txtEmail.Text.Trim();
                    string userName = email.Split('@')[0] + DateTime.Now.ToString("yyyyMMddHHmmtt");
                    string password = txtPassword.Text; //OrderNumberGenerator.GenerateOrderNumber("?#?#?#?#");

                    MembershipCreateStatus createResult;
                    MembershipUser         newUser = Membership.CreateUser(userName, password, email, null, null, true, out createResult);

                    if (createResult == MembershipCreateStatus.Success)
                    {
                        //Assign Customer role to newUser
                        Roles.AddUserToRole(newUser.UserName, "Customer");

                        //log in user.
                        FormsAuthentication.SetAuthCookie(newUser.UserName, false);

                        //Create a Healthy Chef profile for this new user
                        hccUserProfile newProfile = new hccUserProfile
                        {
                            MembershipID   = (Guid)newUser.ProviderUserKey,
                            CreatedBy      = (Membership.GetUser() == null ? Guid.Empty : (Guid)Membership.GetUser().ProviderUserKey),
                            CreatedDate    = DateTime.Now,
                            AccountBalance = 0.00m,
                            IsActive       = true
                        };

                        //save Shipping Address
                        AddressEdit_Shipping1.Save();
                        newProfile.ShippingAddressID = AddressEdit_Shipping1.PrimaryKeyIndex;
                        newProfile.FirstName         = AddressEdit_Shipping1.CurrentAddress.FirstName.Trim();
                        newProfile.LastName          = AddressEdit_Shipping1.CurrentAddress.LastName.Trim();
                        newProfile.ProfileName       = AddressEdit_Shipping1.CurrentAddress.FirstName.Trim();

                        //save Billing Address
                        AddressEdit_Billing1.Save();
                        newProfile.BillingAddressID = AddressEdit_Billing1.PrimaryKeyIndex;

                        //Save all hccProfile information
                        newProfile.Save();

                        //Credit Card
                        try
                        {
                            CreditCard1.CurrentUserProfileID = newProfile.UserProfileID;
                            CreditCard1.Save();
                        }
                        catch { }

                        //Update previously anonymously-created hccCart
                        CurrentCart.AspNetUserID = newProfile.MembershipID;
                        CurrentCart.Save();

                        List <hccCartItem> cartItems = hccCartItem.GetBy(CurrentCart.CartID);
                        cartItems.ForEach(delegate(hccCartItem ci) { ci.UserProfileID = newProfile.UserProfileID; ci.Save(); });

                        //Send E-mail notification to account user
                        try
                        {
                            HealthyChef.Email.EmailController ec = new HealthyChef.Email.EmailController();
                            ec.SendMail_NewUserConfirmation(email, password);
                        }
                        catch { }

                        if (null != userRegistrationModule)
                        {
                            if (!string.IsNullOrEmpty(userRegistrationModule.NotifyEmailAddress))
                            {
                                SecurityEmail.Send(userRegistrationModule.NotifyEmailAddress,
                                                   "New user registration",
                                                   "A new user is waiting for approval. To manage users, click this link:\n"
                                                   + Request.Url.Scheme
                                                   + "://"
                                                   + Request.Url.Authority
                                                   + "/WebModules/Security/Manage/UserList.aspx"
                                                   );
                            }

                            if (!DisableRedirect)
                            {
                                confirmPage = Webpage.GetWebpage(userRegistrationModule.ConfirmationPageNavigationId);
                                if (null != confirmPage)
                                {
                                    Response.Redirect(confirmPage.Path);
                                }
                                else
                                {
                                    if (Request.QueryString["fc"] != null)
                                    {
                                        HttpContext.Current.Response.Redirect("~/cart.aspx?confirm=1", false);
                                    }
                                    else
                                    {
                                        if (newUser != null)
                                        {
                                            HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(newUser.UserName, false));
                                        }
                                        else
                                        {
                                            HttpContext.Current.Response.Redirect("~/", false);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (Request.QueryString["fc"] != null)
                            {
                                HttpContext.Current.Response.Redirect("~/cart.aspx?confirm=1", false);
                            }
                            else
                            {
                                if (newUser != null)
                                {
                                    HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(newUser.UserName, false));
                                }
                                else
                                {
                                    HttpContext.Current.Response.Redirect("~/", false);
                                }
                            }
                        }
                    }
                    else
                    {
                        Msg.ShowError(UserRegistration_Module.GetHumanStatusMessage(createResult));
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #11
0
        void chkUseParentShippingAddress_CheckedChanged(object sender, EventArgs e)
        {
            if (CurrentUserProfile == null)
            {
                CurrentUserProfile = hccUserProfile.GetById(this.PrimaryKeyIndex);
            }

            if (chkUseParentShippingAddress.Checked)
            {
                AddressEdit_SubShipping.Clear();
                AddressEdit_SubShipping.Visible = false;

                if (CurrentUserProfile != null)
                {
                    //CurrentUserProfile.ShippingAddressID = null;
                    CurrentUserProfile.UseParentShipping = true;
                    CurrentUserProfile.Save();
                    Page.Response.Redirect(Page.Request.Url.ToString(), true);
                }
                else
                {
                    if (txtSubProfileName.Text == "" || txtSubFirstName.Text == "" || txtSubLastName.Text == "")
                    {
                        lblSubProfileFeedback.Text      = "Please fill Basic Info before filling Shipping Info";
                        lblSubProfileFeedback.ForeColor = System.Drawing.Color.Red;
                    }
                    else
                    {
                        try
                        {
                            CurrentUserProfile = hccUserProfile.GetById(this.PrimaryKeyIndex);
                            hccUserProfile parentProfile = hccUserProfile.GetById(CurrentParentProfileId);

                            if (CurrentUserProfile == null && parentProfile != null)
                            {
                                hccUserProfile newProfile = new hccUserProfile
                                {
                                    ParentProfileID = CurrentParentProfileId,
                                    CreatedBy       = (Guid)Helpers.LoggedUser.ProviderUserKey,
                                    CreatedDate     = DateTime.Now,
                                    IsActive        = true,
                                    MembershipID    = parentProfile.MembershipID
                                };

                                newProfile.Save();
                                this.PrimaryKeyIndex = newProfile.UserProfileID;
                                CurrentUserProfile   = newProfile;
                            }

                            if (CurrentUserProfile != null)
                            {
                                CurrentUserProfile.IsActive = chkSubIsActive.Checked;

                                if (txtSubProfileName.Text.Trim() != CurrentUserProfile.ProfileName)
                                {
                                    CurrentUserProfile.ProfileName = txtSubProfileName.Text.Trim();
                                }

                                if (txtSubFirstName.Text.Trim() != CurrentUserProfile.FirstName)
                                {
                                    CurrentUserProfile.FirstName = txtSubFirstName.Text.Trim();
                                }

                                if (txtSubLastName.Text.Trim() != CurrentUserProfile.LastName)
                                {
                                    CurrentUserProfile.LastName = txtSubLastName.Text.Trim();
                                }

                                //save addresses
                                if (chkUseParentShippingAddress.Checked)
                                {
                                    if (CurrentUserProfile.ShippingAddressID != 0)
                                    {
                                        CurrentUserProfile.UseParentShipping = true;
                                        //CurrentUserProfile.ShippingAddressID = parentProfile.ShippingAddressID;
                                    }
                                    else
                                    {
                                        CurrentUserProfile.UseParentShipping = true;
                                        CurrentUserProfile.ShippingAddressID = AddressEdit_SubShipping.PrimaryKeyIndex;
                                    }
                                }
                                else
                                {
                                    AddressEdit_SubShipping.Save();
                                    CurrentUserProfile.UseParentShipping = false;
                                    CurrentUserProfile.ShippingAddressID = AddressEdit_SubShipping.PrimaryKeyIndex;
                                }

                                //preferences
                                SubProfilePrefsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                                SubProfilePrefsEdit1.Save();

                                //allergens
                                SubProfileAllgsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                                SubProfileAllgsEdit1.Save();

                                CurrentUserProfile.Save();


                                //DisplayProfileTabs(false);
                                lblSubProfileFeedback.Text      = "Sub-Profile Saved - " + DateTime.Now.ToString("MM/dd/yyy hh:mm:ss");
                                lblSubProfileFeedback.ForeColor = System.Drawing.Color.Green;

                                OnSaved(new ControlSavedEventArgs(this.PrimaryKeyIndex));
                            }
                        }
                        catch
                        {
                            throw;
                        }
                    }
                }
            }
            else
            {
                AddressEdit_SubShipping.Visible = true;

                if (CurrentUserProfile != null)
                {
                    CurrentUserProfile.UseParentShipping = false;
                    CurrentUserProfile.Save();
                }
            }
        }
Пример #12
0
        protected override void SaveForm()
        {
            try
            {
                CurrentUserProfile = hccUserProfile.GetById(this.PrimaryKeyIndex);
                hccUserProfile parentProfile = hccUserProfile.GetById(CurrentParentProfileId);

                if (CurrentUserProfile == null && parentProfile != null)
                {
                    hccUserProfile newProfile = new hccUserProfile
                    {
                        ParentProfileID = CurrentParentProfileId,
                        CreatedBy       = (Guid)Helpers.LoggedUser.ProviderUserKey,
                        CreatedDate     = DateTime.Now,
                        IsActive        = true,
                        MembershipID    = parentProfile.MembershipID
                    };

                    newProfile.Save();
                    this.PrimaryKeyIndex = newProfile.UserProfileID;
                    CurrentUserProfile   = newProfile;
                }

                if (CurrentUserProfile != null)
                {
                    CurrentUserProfile.IsActive = chkSubIsActive.Checked;

                    if (txtSubProfileName.Text.Trim() != CurrentUserProfile.ProfileName)
                    {
                        CurrentUserProfile.ProfileName = txtSubProfileName.Text.Trim();
                    }

                    if (txtSubFirstName.Text.Trim() != CurrentUserProfile.FirstName)
                    {
                        CurrentUserProfile.FirstName = txtSubFirstName.Text.Trim();
                    }

                    if (txtSubLastName.Text.Trim() != CurrentUserProfile.LastName)
                    {
                        CurrentUserProfile.LastName = txtSubLastName.Text.Trim();
                    }

                    //save addresses
                    if (chkUseParentShippingAddress.Checked)
                    {
                        if (CurrentUserProfile.ShippingAddressID != 0)
                        {
                            CurrentUserProfile.UseParentShipping = true;
                            //CurrentUserProfile.ShippingAddressID = parentProfile.ShippingAddressID;
                        }
                        else
                        {
                            CurrentUserProfile.UseParentShipping = true;
                            CurrentUserProfile.ShippingAddressID = AddressEdit_SubShipping.PrimaryKeyIndex;
                        }
                    }
                    else
                    {
                        AddressEdit_SubShipping.Save();
                        CurrentUserProfile.UseParentShipping = false;
                        CurrentUserProfile.ShippingAddressID = AddressEdit_SubShipping.PrimaryKeyIndex;
                    }

                    //preferences
                    SubProfilePrefsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                    SubProfilePrefsEdit1.Save();

                    //allergens
                    SubProfileAllgsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID;
                    SubProfileAllgsEdit1.Save();

                    CurrentUserProfile.Save();
                }

                //DisplayProfileTabs(false);
                lblSubProfileFeedback.Text      = "Sub-Profile Saved - " + DateTime.Now.ToString("MM/dd/yyy hh:mm:ss");
                lblSubProfileFeedback.ForeColor = System.Drawing.Color.Green;

                OnSaved(new ControlSavedEventArgs(this.PrimaryKeyIndex));
                ClearForm();
            }
            catch
            {
                throw;
            }
        }