protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); HttpContext ctx = System.Web.HttpContext.Current; ViewBag.year = UDF.GetYearCookie(ctx); ViewBag.make = UDF.GetMakeCookie(ctx); ViewBag.model = UDF.GetModelCookie(ctx); ViewBag.style = UDF.GetStyleCookie(ctx); ViewBag.vehicleID = UDF.GetVehicleCookie(ctx); // Get the theme ID int themeID = new Theme().getTheme(ctx); ViewBag.themeID = themeID; if (themeID > 0) { // if there is an active theme, get the files string cname = this.ControllerContext.Controller.ToString(); Dictionary<int, List<ThemeFile>> themefiles = new Theme().getFiles(ctx,UDF.GetControllerName(cname)); ViewBag.themefiles = themefiles; } // We're gonna dump our Customer Session object out Customer customer = new Customer(); customer.GetFromStorage(ctx); Settings settings = new Settings(); ViewBag.settings = settings; ViewBag.customer = customer; }
public async Task<ActionResult> Index() { HttpContext ctx = System.Web.HttpContext.Current; var pcats = CURTAPI.GetParentCategoriesAsync(); await Task.WhenAll(new Task[] { pcats }); ViewBag.parent_cats = await pcats; // Instantiate our Customer object Customer cust = new Customer(); // Retrieve from Session/Cookie cust.GetFromStorage(ctx); if (!cust.LoggedIn(ctx)) { return RedirectToAction("Index","Authenticate"); } // Get the Customer record cust.Get(); cust.BindAddresses(); ViewBag.countries = UDF.GetCountries(); ViewBag.cust = cust; ViewBag.error = TempData["error"]; return View(); }
public ActionResult ResetPassword() { HttpContext ctx = System.Web.HttpContext.Current; Customer cust = new Customer(); cust.GetFromStorage(ctx); if (!cust.LoggedIn(ctx)) { return RedirectToAction("Index", "Authenticate"); } string message = ""; try { string current = Request.Form["current"]; string newpw = Request.Form["new"]; string confirm = Request.Form["confirm"]; if (String.IsNullOrEmpty(current) || String.IsNullOrEmpty(newpw) || String.IsNullOrEmpty(confirm)) { throw new Exception("You must enter all password fields. Try Again"); } cust.ValidateCurrentPassword(current); cust.ValidatePasswords(newpw, confirm); cust.UpdatePassword(); message = "Your password was successfully updated."; } catch (Exception e) { message = e.Message; } return RedirectToAction("Password", new { message = message }); }
public ActionResult DeleteAddress(int id = 0) { Customer cust = new Customer(); cust.GetFromStorage(); Address a = new Address().Get(id); cust.ClearAddress(a.ID); if (a.cust_id == cust.ID) { a.Delete(id); } return RedirectToAction("Addresses"); }
public ActionResult Login(string email = "", string password = "", int remember = 0) { try { HttpContext ctx = System.Web.HttpContext.Current; /** * Store any Customer object from Session/Cookie into a tmp object * We'll remove the cart from the tmp object and add it to our new Authenticated Customer */ Customer tmp = new Customer(); tmp.GetFromStorage(ctx); Cart tmp_cart = tmp.Cart; string enc_password = UDF.EncryptString(password); EcommercePlatformDataContext db = new EcommercePlatformDataContext(); Customer cust = new Customer { email = email, password = enc_password }; cust.Login(); cust.password = "******"; if (tmp_cart.CartItems.Count == 0) { try { Cart cust_cart = tmp_cart; cust_cart = db.Carts.Where(x => x.cust_id == cust.ID).Where(x => x.payment_id == 0).OrderByDescending(x => x.last_updated).First<Cart>(); tmp_cart.RemoveCart(); tmp.Cart = cust_cart; } catch { tmp_cart.UpdateCart(ctx, cust.ID); } } else { tmp_cart.UpdateCart(ctx, cust.ID); } HttpCookie cook = new HttpCookie("hdcart", tmp.Cart.ID.ToString()); if (remember != 0) { cook.Expires = DateTime.Now.AddDays(30); } Response.Cookies.Add(cook); HttpCookie authed = new HttpCookie("authenticated", "1"); if (remember != 0) { cook.Expires = DateTime.Now.AddDays(30); } Response.Cookies.Add(authed); return RedirectToAction("Index", "Cart"); } catch (Exception e) { TempData["error"] = e.Message; return RedirectToAction("Index"); } }
//[RequireHttps] public ActionResult AddBillingAddress() { try { // Create Customer Customer customer = new Customer(); customer.GetFromStorage(); if (!customer.LoggedIn()) { return RedirectToAction("Index", "Authenticate", new { referrer = "https://" + Request.Url.Host + "/Cart/Checkout" }); } 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) { customer.SetShippingDefaultAddress(billing.ID); } // Retrieve Customer from Sessions/Cookie customer.Cart.SetBilling(billing.ID); if (customer.Cart.ship_to == 0) { customer.Cart.SetShipping(billing.ID); } } else { UDF.ExpireCart(customer.ID); return RedirectToAction("index"); } } catch { } return RedirectToAction("shipping"); }
public string AddAjax(int id = 0, int qty = 0) { // Create Customer Customer customer = new Customer(); // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(); if (customer.Cart.payment_id == 0) { customer.Cart.Add(id, qty); } else { UDF.ExpireCart(customer.ID); } return getCart(); }
public async Task<ActionResult> Password(string message = "") { HttpContext ctx = System.Web.HttpContext.Current; var pcats = CURTAPI.GetParentCategoriesAsync(); await Task.WhenAll(new Task[] { pcats }); ViewBag.parent_cats = await pcats; ViewBag.message = message; Customer cust = new Customer(); cust.GetFromStorage(ctx); if (!cust.LoggedIn(ctx)) { return RedirectToAction("Index", "Authenticate"); } ViewBag.cust = cust; return View(); }
public ActionResult Index() { // Instantiate our Customer object Customer cust = new Customer(); // Retrieve from Session/Cookie cust.GetFromStorage(); // Get the Customer record cust.Get(); cust.BindAddresses(); ViewBag.countries = UDF.GetCountries(); ViewBag.cust = cust; ViewBag.error = TempData["error"]; return View(); }
public ActionResult Add(int id = 0, int qty = 1) { // Create Customer Customer customer = new Customer(); // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(); // Add the item to the cart if (customer.Cart.payment_id == 0) { customer.Cart.Add(id,qty); // Serialize the Customer back to where it came from return RedirectToAction("Index"); } else { UDF.ExpireCart(customer.ID); return RedirectToAction("Index"); } }
public async Task<ActionResult> Index() { HttpContext ctx = System.Web.HttpContext.Current; var pcats = CURTAPI.GetParentCategoriesAsync(); await Task.WhenAll(new Task[] { pcats }); ViewBag.parent_cats = await pcats; // Create Customer Customer customer = new Customer(); // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(ctx); // Create Cart object from customer Cart cart = customer.Cart; // Get the api response from the parts in this Cart cart.GetParts(); ViewBag.cart = cart; return View(); }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); // Get the vehicle years List<double> years = CURTAPI.GetYears(); ViewBag.years = years; // Get the parent categories List<APICategory> parent_cats = CURTAPI.GetParentCategories(); ViewBag.parent_cats = parent_cats; // We're gonna dump our Customer Session object out Customer customer = new Customer(); customer.GetFromStorage(); Settings settings = new Settings(); ViewBag.settings = settings; ViewBag.customer = customer; }
public ActionResult AddAddress() { try { // Create Customer Customer customer = new Customer(); customer.GetFromStorage(); if (!customer.LoggedIn()) { return RedirectToAction("Index", "Authenticate"); } Address address = new Address(); // Build out our Billing object address = new Address { first = Request.Form["first"], last = Request.Form["last"], street1 = Request.Form["street1"], street2 = (Request.Form["street2"].Trim() == "") ? null : Request.Form["street2"].Trim(), city = Request.Form["city"], postal_code = Request.Form["zip"], residential = (Request.Form["residential"] == null) ? false : true, active = true }; try { address.state = Convert.ToInt32(Request.Form["state"]); } catch (Exception) { throw new Exception("You must select a state/province."); } address.Save(customer.ID); } catch (Exception e) { if (e.Message.ToLower().Contains("a potentially dangerous")) { throw new HttpException(403, "Forbidden"); } } return RedirectToAction("Addresses"); }
//[RequireHttps] public ActionResult ChooseShipping(int id = 0) { // Create Customer Customer customer = new Customer(); HttpContext ctx = System.Web.HttpContext.Current; // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(ctx); if (customer.Cart.payment_id == 0) { if (customer.shippingID == 0) { customer.SetShippingDefaultAddress(id); } customer.Cart.SetShipping(id); return RedirectToAction("Shipping"); } else { UDF.ExpireCart(ctx, customer.ID); return RedirectToAction("index"); } }
//[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 }); }
public string getCart() { Customer customer = new Customer(); HttpContext ctx = System.Web.HttpContext.Current; // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(ctx); Cart cart = customer.Cart; Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); settings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; Newtonsoft.Json.Formatting format = Newtonsoft.Json.Formatting.None; return Newtonsoft.Json.JsonConvert.SerializeObject(cart,format,settings); }
//[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"); }
public ActionResult Remove(int id = 0) { // Create Customer Customer customer = new Customer(); HttpContext ctx = System.Web.HttpContext.Current; // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(ctx); if (customer.Cart.payment_id == 0) { customer.Cart.Remove(ctx, id); } else { UDF.ExpireCart(ctx, customer.ID); } return RedirectToAction("Index"); }
public string RemoveAjax(int id = 0) { // Create Customer Customer customer = new Customer(); HttpContext ctx = System.Web.HttpContext.Current; // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(ctx); if (customer.Cart.payment_id == 0) { customer.Cart.Remove(ctx, id); } else { UDF.ExpireCart(ctx, customer.ID); } return Response.Cookies["cart"].Value; }
public ActionResult ChooseShippingType(string shipping_type = "") { Customer customer = new Customer(); // Retrieve Customer from Sessions/Cookie HttpContext ctx = System.Web.HttpContext.Current; customer.GetFromStorage(ctx); if (customer.Cart.payment_id == 0) { decimal shipping_price = 0; string shiptype = ""; try { string[] typesplit = shipping_type.Split('|'); shiptype = typesplit[0]; shipping_price = Convert.ToDecimal(typesplit[1]); customer.Cart.setShippingType(shiptype, shipping_price); // We need to calculate the tax now that we know the shipping state customer.Cart.SetTax(); if (customer.Cart.Validate()) { return RedirectToAction("Index", "Payment"); } else if (customer.Cart.bill_to == 0 || customer.Cart.ship_to == 0) { return RedirectToAction("Checkout"); } else { return RedirectToAction("Index"); } } catch { return RedirectToAction("Checkout", "Cart"); } } else { UDF.ExpireCart(ctx, customer.ID); return RedirectToAction("Index"); } }
public string RemoveAjax(int id = 0) { // Create Customer Customer customer = new Customer(); // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(); if (customer.Cart.payment_id == 0) { customer.Cart.Remove(id); } else { UDF.ExpireCart(customer.ID); } return Response.Cookies["cart"].Value; }
public ActionResult UpgradeShipping(string type = ""){ HttpContext ctx = System.Web.HttpContext.Current; ShippingResponse resp = getShipping(ctx); if (resp.Status_Description == "OK") { ShipmentRateDetails details = resp.Result.FirstOrDefault<ShipmentRateDetails>(); RateDetail rate = details.Rates.FirstOrDefault<RateDetail>(); Customer customer = new Customer(); // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(ctx); decimal shipping_price = Convert.ToDecimal(rate.NetCharge.Key); string shipping_type = details.ServiceType; customer.Cart.setShippingType(shipping_type, shipping_price); } TempData["shipping_response"] = resp; return RedirectToAction("shipping"); }
public ActionResult Remove(int id = 0) { // Create Customer Customer customer = new Customer(); // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(); if (customer.Cart.payment_id == 0) { customer.Cart.Remove(id); } else { UDF.ExpireCart(customer.ID); } return RedirectToAction("Index"); }
public ActionResult Save() { HttpContext ctx = System.Web.HttpContext.Current; Customer cust = new Customer(); try { cust.GetFromStorage(ctx); if (!cust.LoggedIn(ctx)) { return RedirectToAction("Index", "Authenticate"); } #region Basic Information string email = cust.email; if (Request.Form["email"] != null && Request.Form["email"].Length > 0) { email = Request.Form["email"]; } if (email != cust.email) { // Make sure we don't have an account with this e-mail address if (Customer.CheckCustomerEmail(email)) { throw new Exception("An account using the E-Mail address you provided already exists."); } } string fname = cust.fname; if(Request.Form["fname"] != null && Request.Form["fname"].Length > 0){ fname = Request.Form["fname"]; } string lname = cust.lname; if(Request.Form["lname"] != null && Request.Form["lname"].Length > 0){ lname = Request.Form["lname"]; } string phone = cust.phone; if(Request.Form["phone"] != null && Request.Form["phone"].Length > 0){ phone = Request.Form["phone"]; } int receiveOffers = cust.receiveOffers; int receiveNewsletter = cust.receiveNewsletter; if (Request.Form["receiveOffers"] != null) { try { receiveOffers = Convert.ToInt32(Request.Form["receiveOffers"]); } catch (Exception) { } } else { receiveOffers = 0; } if (Request.Form["receiveNewsletter"] != null) { try { receiveNewsletter = Convert.ToInt32(Request.Form["receiveNewsletter"]); } catch (Exception) { } } else { receiveNewsletter = 0; } cust.Update(email,fname,lname,phone,receiveOffers,receiveNewsletter); #endregion TempData["error"] = "You're account has been successfully updated."; return Redirect("/Account"); } catch (Exception e) { if (e.Message.ToLower().Contains("a potentially dangerous")) { throw new HttpException(403, "Forbidden"); } TempData["customer"] = cust; TempData["error"] = "Failed to save your account information. " + e.Message + e.StackTrace; return Redirect("/Account"); } }
public ActionResult SetShippingDefault(int id = 0) { HttpContext ctx = System.Web.HttpContext.Current; Customer cust = new Customer(); cust.GetFromStorage(ctx); if (!cust.LoggedIn(ctx)) { return RedirectToAction("Index", "Authenticate"); } Address a = new Address().Get(id); if (a.cust_id == cust.ID) { cust.SetShippingDefaultAddress(id); cust.BindAddresses(); } return RedirectToAction("Addresses"); }
public ActionResult DeleteAddress(int id = 0) { HttpContext ctx = System.Web.HttpContext.Current; Customer cust = new Customer(); cust.GetFromStorage(ctx); if (!cust.LoggedIn(ctx)) { return RedirectToAction("Index", "Authenticate"); } Address a = new Address().Get(id); cust.ClearAddress(a.ID); if (a.cust_id == cust.ID) { a.Delete(id); } return RedirectToAction("Addresses"); }
public ShippingResponse getShipping(HttpContext ctx) { Customer customer = new Customer(); Settings settings = ViewBag.settings; customer.GetFromStorage(ctx); FedExAuthentication auth = new FedExAuthentication { AccountNumber = Convert.ToInt32(settings.Get("FedExAccount")), Key = settings.Get("FedExKey"), Password = settings.Get("FedExPassword"), CustomerTransactionId = "", MeterNumber = Convert.ToInt32(settings.Get("FedExMeter")) }; customer.Cart.BindAddresses(); ShippingAddress destination = new ShippingAddress(); try { destination = customer.Cart.Shipping.getShipping(); } catch (Exception) { Response.Redirect("/Cart/Checkout"); } DistributionCenter d = new DistributionCenter().GetNearest(customer.Cart.Shipping.GeoLocate()); ShippingAddress origin = d.getAddress().getShipping(); List<int> parts = new List<int>(); foreach (CartItem item in customer.Cart.CartItems) { for (int i = 1; i <= item.quantity; i++) { parts.Add(item.partID); } } ShippingResponse response = CURTAPI.GetShipping(auth, origin, destination, parts); return response; }
public string AddAjax(int id = 0, int qty = 0) { HttpContext ctx = System.Web.HttpContext.Current; // Create Customer Customer customer = new Customer(); // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(ctx); if (customer.Cart.payment_id == 0) { customer.Cart.Add(ctx,id, qty); } else { UDF.ExpireCart(ctx,customer.ID); } return getCart(); }
public ActionResult Update(int id = 0, int qty = 1) { try { // Create Customer Customer customer = new Customer(); HttpContext ctx = System.Web.HttpContext.Current; // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(ctx); if (customer.Cart.payment_id == 0) { customer.Cart.Update(ctx, id, qty); } else { UDF.ExpireCart(ctx, customer.ID); } } catch (Exception e) { if (e.Message.ToLower().Contains("a potentially dangerous")) { throw new HttpException(403, "Forbidden"); } } return RedirectToAction("Index"); }
public ActionResult UpgradeShipping(string type = "") { ShippingResponse resp = getShipping(); if (resp.Status_Description == "OK") { ShipmentRateDetails details = resp.Result.FirstOrDefault<ShipmentRateDetails>(); RateDetail rate = details.Rates.FirstOrDefault<RateDetail>(); Customer customer = new Customer(); // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(); if (!customer.LoggedIn()) { return RedirectToAction("Index", "Authenticate", new { referrer = "https://" + Request.Url.Host + "/Cart/Checkout" }); } decimal shipping_price = Convert.ToDecimal(rate.NetCharge.Key); string shipping_type = details.ServiceType; customer.Cart.setShippingType(shipping_type, shipping_price); } TempData["shipping_response"] = resp; return RedirectToAction("shipping"); }