예제 #1
0
        //[RequireHttps]
        public ActionResult AddShippingAddress() {
            string error = "";
            try {
                // Create Customer
                Customer customer = new Customer();
                HttpContext ctx = System.Web.HttpContext.Current;
                customer.GetFromStorage(ctx);

                Address shipping = new Address();
                // Build out our Billing object
                shipping = new Address {
                    first = Request.Form["sfirst"],
                    last = Request.Form["slast"],
                    street1 = Request.Form["sstreet1"],
                    street2 = Request.Form["sstreet2"],
                    city = Request.Form["scity"],
                    postal_code = Request.Form["szip"],
                    residential = (Request.Form["sresidential"] == null) ? false : true,
                    active = true
                };
                try {
                    shipping.state = Convert.ToInt32(Request.Form["sstate"]);
                } catch (Exception) {
                    throw new Exception("You must select a shipping state/province.");
                }
                if (shipping.isPOBox()) {
                    throw new Exception("You cannot ship to a PO Box.");
                }
                //shipping.GeoLocate();
                shipping.Save(customer.ID);

                // Retrieve Customer from Sessions/Cookie
                customer.Cart.SetShipping(shipping.ID);
            } catch (Exception e) {
                error = e.Message;
            }

            return RedirectToAction("shipping", new { error = error });
        }
예제 #2
0
        //[RequireHttps]
        public ActionResult AddBillingAddress() {
            try {
                // Create Customer
                Customer customer = new Customer();
                HttpContext ctx = System.Web.HttpContext.Current;
                customer.GetFromStorage(ctx);

                if (customer.Cart.payment_id == 0) {
                    Address billing = new Address();
                    // Build out our Billing object
                    billing = new Address {
                        first = Request.Form["bfirst"],
                        last = Request.Form["blast"],
                        street1 = Request.Form["bstreet1"],
                        street2 = Request.Form["bstreet2"],
                        city = Request.Form["bcity"],
                        postal_code = Request.Form["bzip"],
                        residential = (Request.Form["bresidential"] == null) ? false : true,
                        active = true
                    };
                    try {
                        billing.state = Convert.ToInt32(Request.Form["bstate"]);
                    } catch (Exception) {
                        throw new Exception("You must select a billing state/province.");
                    }
                    billing.Save(customer.ID);
                    if (customer.billingID == 0) {
                        customer.SetBillingDefaultAddress(billing.ID);
                    }
                    if (customer.shippingID == 0 && !billing.isPOBox()) {
                        customer.SetShippingDefaultAddress(billing.ID);
                    }

                    // Retrieve Customer from Sessions/Cookie

                    customer.Cart.SetBilling(billing.ID);
                    if (customer.Cart.ship_to == 0 && !billing.isPOBox()) {
                        customer.Cart.SetShipping(billing.ID);
                    }
                } else {
                    UDF.ExpireCart(ctx, customer.ID);
                    return RedirectToAction("index");
                }
            } catch { }

            return RedirectToAction("shipping");
        }