예제 #1
0
        protected void ButtonContactActionUpdate_Click(object sender, EventArgs e)
        {
            ClearAlerts();
            try
            {
                int i = int.Parse(Request.QueryString["id"] != null ? Request.QueryString["id"] : "0");
                var newContact = theGateContext.Contacts.FirstOrDefault(c => c.contactID == i);

                newContact = LoadContact(newContact);

                if (pnlShippingAddress.Visible)
                {
                    if (newContact.shippingAddress == null)
                    {
                        var sa = new Address()
                        {
                            line1 = txtShippingAddress1.Text,
                            line2 = txtShippingAddress2.Text,
                            city = txtShippingCity.Text,
                            state = ddlShippingProvince.SelectedValue,
                            zipcode = txtShippingPostalCode.Text
                        };
                        theGateContext.Addresses.Add(sa);
                        theGateContext.SaveChanges();
                        newContact.shippingAddress = sa.addressID;
                    }
                    else
                    {
                        newContact.Address.line1 = txtShippingAddress1.Text;
                        newContact.Address.line2 = txtShippingAddress2.Text;
                        newContact.Address.city = txtShippingCity.Text;
                        newContact.Address.state = ddlShippingProvince.SelectedValue;
                        newContact.Address.zipcode = txtShippingPostalCode.Text;
                    }
                }

                if (pnlBillingAddress.Visible)
                {
                    if (ckbSameAsShipping.Checked)
                        newContact.billingAddress = newContact.shippingAddress;
                    else
                    {
                        if (newContact.billingAddress == null || newContact.shippingAddress == newContact.billingAddress)
                        {
                            var ba = new Address()
                            {
                                line1 = txtBillingAddress1.Text,
                                line2 = txtBillingAddress2.Text,
                                city = txtBillingCity.Text,
                                state = ddlBillingProvince.SelectedValue,
                                zipcode = txtBillingPostalCode.Text
                            };
                            theGateContext.Addresses.Add(ba);
                            theGateContext.SaveChanges();
                            newContact.billingAddress = ba.addressID;
                        }
                        else
                        {
                            newContact.Address1.line1 = txtBillingAddress1.Text;
                            newContact.Address1.line2 = txtBillingAddress2.Text;
                            newContact.Address1.city = txtBillingCity.Text;
                            newContact.Address1.state = ddlBillingProvince.SelectedValue;
                            newContact.Address1.zipcode = txtBillingPostalCode.Text;
                        }
                    }
                }

                theGateContext.SaveChanges();
                ShowSuccess("Contact successfully updated.");
            }
            catch (Exception ex)
            {
                ShowError("Error updating product: " + ex.Message);
            }
        }
예제 #2
0
        protected void sSaveBtn_Click(object sender, EventArgs e)
        {
            if (Session["newBilling"].ToString() == "true")
            {
                var address = new Address()
                {
                    line1 = line1TxtBox.Text,
                    line2 = line2TxtBox.Text,
                    city = cityTxtBox.Text,
                    state = stateTxtBox.Text,
                    zipcode = zipcodeTxtBox.Text
                };

                theGateContext.Addresses.Add(address);
                theGateContext.SaveChanges();

                int billingAddressID = _address.addressID;
                contact.billingAddress = billingAddressID;
                theGateContext.SaveChanges();
                Session["newBilling"] = "false";
            }
            else if (Session["newBilling"].ToString() == "false")
            {
                getAddress.line1 = line1TxtBox.Text;
                getAddress.line2 = line2TxtBox.Text;
                getAddress.city = cityTxtBox.Text;
                getAddress.state = stateTxtBox.Text;
                getAddress.zipcode = zipcodeTxtBox.Text;
                theGateContext.SaveChanges();
            }

            if (Session["newShipping"].ToString() == "true")
            {
                var address = new Address()
                {
                    line1 = sline1TxtBox.Text,
                    line2 = sline2TxtBox.Text,
                    city = scityTxtBox.Text,
                    state = sstateTxtBox.Text,
                    zipcode = szipcodeTxtBox.Text
                };

                theGateContext.Addresses.Add(address);
                theGateContext.SaveChanges();

                int shippingAddressID = _saddress.addressID;
                contact.shippingAddress = shippingAddressID;
                theGateContext.SaveChanges();
                Session["newShipping"] = "false";
            }
            else if (Session["newShipping"].ToString() == "false")
            {
                sgetAddress.line1 = sline1TxtBox.Text;
                sgetAddress.line2 = sline2TxtBox.Text;
                sgetAddress.city = scityTxtBox.Text;
                sgetAddress.state = sstateTxtBox.Text;
                sgetAddress.zipcode = szipcodeTxtBox.Text;
                theGateContext.SaveChanges();
            }
            successLbl.Visible = true;
        }