public void Calculate(Cart cart, int prefID) { List <ShippingOrderValue> shippingSettings = ShippingDAL.GetShippingOrderValue(ShippingOptionType.TotalAmount, _isRushShipping, prefID).OrderBy(s => s.OrderTotal).ToList(); decimal cartSubtotal = cart.SubTotal; int totalShippingSettings = shippingSettings.Count; for (int i = 0; i < totalShippingSettings; i++) { ShippingOrderValue currentSetting = shippingSettings[i]; if (cartSubtotal <= currentSetting.OrderTotal || i == totalShippingSettings - 1) { // add additional shipping charge by specified key ShippingCharge shippingCharge = ShippingDAL.GetShippingCharge(prefID, cart.ShippingChargeKey); if (shippingCharge != null) { cart.AdditionalShippingCharge = shippingCharge.Cost; } if (_isRushShipping) { cart.RushShippingCost = currentSetting.Cost; } else { cart.ShippingCost = currentSetting.Cost; } break; } } }
public void Calculate(ShoppingManagement.Cart cart, int prefID) { ShippingPref shippingGetShippingPref = ShippingDAL.GetShippingPref().Where(p => p.PrefId == prefID).FirstOrDefault(); if (shippingGetShippingPref != null) { if (cart.SubTotal > 0) //Sri: Reset shipping calculation if there are no items in the cart { // add additional shipping charge by specified key ShippingCharge shippingCharge = ShippingDAL.GetShippingCharge(prefID, cart.ShippingChargeKey); if (shippingCharge != null) { cart.AdditionalShippingCharge = shippingCharge.Cost; } if (_isRushShipping) { cart.RushShippingCost = shippingGetShippingPref.RushShippingCost; } else { cart.ShippingCost = (shippingGetShippingPref.flatShipping ?? 0); } } } else { throw new InvalidOperationException("Missing shipping preferences"); } }
public List <string> ToStringValues() { return(new List <string>() { Id, Datestamp, FullName, FirstName, LastName, Address1, Address2, City, State, Zip, Country, Phone, Email, CardName, CardNumber, CardExpiry, TaxCharge.ToString(), ShippingCharge.ToString(), Total.ToString(), CardCvv2, Ip, GiftCard, GiftCardAmountUsed.ToString(), AuthCode, HomeDeliveryCharge.ToString(), CcRefNo }); }
public ActionResult DeleteConfirmed(int id) { ShippingCharge shippingcharge = db.ShippingCharges.Find(id); db.ShippingCharges.Remove(shippingcharge); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Checkout(CheckoutViewModel checkoutViewModel) { UserHelper userHelper = new UserHelper(); ShippingCharge shippingCharge = db.ShippingCharges.FirstOrDefault(); List <CartViewModel> cartItems = GetCartItems(); decimal totalBookWeight = cartItems.Sum(k => (k.BookWeight * k.BookQuantity)); decimal totalShippingCharges = (totalBookWeight / shippingCharge.Weight) * shippingCharge.ShippingRate; Order order = new Order(); order.UserId = userHelper.GetLoginUserId(); order.Status = "processing"; order.Createdate = DateTime.Now; order.TotalWeight = totalBookWeight; order.TotalShippingCharges = totalShippingCharges; db.Orders.Add(order); db.SaveChanges(); foreach (var item in cartItems) { OrderDetail orderDetail = new OrderDetail(); orderDetail.BookId = item.BookId; orderDetail.Quantity = item.BookQuantity; orderDetail.BookPrice = item.BookPrice; orderDetail.BookWeight = item.BookWeight; orderDetail.OrderId = order.OrderId; orderDetail.Createdate = DateTime.Now; db.OrderDetails.Add(orderDetail); db.SaveChanges(); } CustomerDetail customerDetail = new CustomerDetail(); customerDetail.Customername = checkoutViewModel.CustomerName; customerDetail.ShippingAddress = checkoutViewModel.ShippingAddress; customerDetail.PhoneNo = checkoutViewModel.PhoneNo; customerDetail.OrderId = order.OrderId; customerDetail.Createdate = DateTime.Now; db.CustomerDetails.Add(customerDetail); db.SaveChanges(); EmptyCart(); ThankyouViewModel thankyouViewModel = new ThankyouViewModel(); thankyouViewModel.OrderId = order.OrderId; thankyouViewModel.CustomerName = customerDetail.Customername; thankyouViewModel.ShippingAddress = customerDetail.ShippingAddress; return(View("~/Views/Cart/Thankyou.cshtml", thankyouViewModel)); }
public void Calculate(Cart cart, int prefID) { List <SkuShipping> skuShippingItems = ShippingDAL.GetSkuShipping(_isRushShipping, prefID); decimal shippingCost = 0; int totalShippingSettings = skuShippingItems.Count; for (int i = 0; i < totalShippingSettings; i++) { SkuShipping currentSetting = skuShippingItems[i]; if (cart.CartItems.Exists(c => c.SkuId == currentSetting.SkuId)) { bool withQuantity = false; Sku s = new Sku(); s.SkuId = currentSetting.SkuId; s.LoadAttributeValues(); if (s.AttributeValues.ContainsKey("shippingwithquantity")) { if (s.AttributeValues["shippingwithquantity"].BooleanValue) { withQuantity = true; } } if (withQuantity) { foreach (Sku st in cart.CartItems) { if (st.SkuId == currentSetting.SkuId) { shippingCost += currentSetting.Cost * st.Quantity; } } } else { shippingCost += currentSetting.Cost; } } } // add additional shipping charge by specified key ShippingCharge shippingCharge = ShippingDAL.GetShippingCharge(prefID, cart.ShippingChargeKey); if (shippingCharge != null) { cart.AdditionalShippingCharge = shippingCharge.Cost; } if (_isRushShipping) { cart.RushShippingCost = shippingCost; } else { cart.ShippingCost = shippingCost; } }
public void Calculate(Cart cart, int prefID) { List <ShippingOrderValue> shippingSettings = ShippingDAL.GetShippingOrderValue(ShippingOptionType.Weight, _isRushShipping, prefID).OrderBy(s => s.OrderTotal).ToList(); bool withQuantity = false; decimal cartWeight; SitePreference sp = CSFactory.GetCacheSitePref(); if (!sp.AttributeValuesLoaded) { sp.LoadAttributeValues(); } if (sp.AttributeValues.ContainsKey("qtyinweightbasedshipping")) { if (sp.AttributeValues["qtyinweightbasedshipping"].BooleanValue) { withQuantity = true; } } if (withQuantity) { cartWeight = cart.CartItems.Sum(c => c.Weight * c.Quantity); } else { cartWeight = cart.CartItems.Sum(c => c.Weight); } int totalShippingSettings = shippingSettings.Count; for (int i = 0; i < totalShippingSettings; i++) { ShippingOrderValue currentSetting = shippingSettings[i]; if (cartWeight <= currentSetting.OrderTotal || i == totalShippingSettings - 1) { // add additional shipping charge by specified key ShippingCharge shippingCharge = ShippingDAL.GetShippingCharge(prefID, cart.ShippingChargeKey); if (shippingCharge != null) { cart.AdditionalShippingCharge = shippingCharge.Cost; } if (_isRushShipping) { cart.RushShippingCost = currentSetting.Cost; } else { cart.ShippingCost = currentSetting.Cost; } break; } } }
public ActionResult Edit([Bind(Include = "ShippingRate,Weight,Createdate,id")] ShippingCharge shippingcharge) { if (ModelState.IsValid) { db.Entry(shippingcharge).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shippingcharge)); }
public ActionResult Create([Bind(Include = "ShippingRate,Weight,Createdate,id")] ShippingCharge shippingcharge) { if (ModelState.IsValid) { db.ShippingCharges.Add(shippingcharge); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shippingcharge)); }
// GET: /Admin/ShippingCharge/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ShippingCharge shippingcharge = db.ShippingCharges.Find(id); if (shippingcharge == null) { return(HttpNotFound()); } return(View(shippingcharge)); }
public ActionResult ViewCart() { List <CartViewModel> cartItems = GetCartItems(); ShippingCharge shippingCharge = db.ShippingCharges.FirstOrDefault(); decimal totalBookWeight = cartItems.Sum(k => (k.BookWeight * k.BookQuantity)); decimal subTotal = cartItems.Sum(k => k.SubTotal); decimal totalShippingCharges = (totalBookWeight / shippingCharge.Weight) * shippingCharge.ShippingRate; ViewData["TotalWeight"] = totalBookWeight; ViewData["SubTotal"] = subTotal; ViewData["ShippingCharges"] = totalShippingCharges; ViewData["NetTotal"] = subTotal + totalShippingCharges; return(View(cartItems)); }
protected void lbAddShippingCharge_Command(object sender, CommandEventArgs e) { if (Page.IsValid) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { ShippingCharge shippingCharge = new ShippingCharge() { PrefId = CurrentSitePreferenceId, Key = string.Empty, Cost = 0, CreateDate = DateTime.Now }; context.ShippingCharges.InsertOnSubmit(shippingCharge); context.SubmitChanges(); BindAll(); } } }
protected void btnSave_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e) { if (e.CommandName == "Save") { ShippingOptionType option = ShippingOptionType.TotalAmount; ShippingOptionType optionRush = ShippingOptionType.TotalAmount; if (pnlOrderVal.Visible) { option = ShippingOptionType.TotalAmount; if (this.rptItems.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptItems.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } } } } } //end if for Shipping OrderValue if (pnlWeight.Visible) { option = ShippingOptionType.Weight; if (this.rptOrderWeight.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptOrderWeight.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } } } } } //end if for Shipping OrderWeight if (pnlSkuItem.Visible) { option = ShippingOptionType.SkuBased; if (this.rptSkuItem.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptSkuItem.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text); TextBox txtCostVal = (TextBox)lst.FindControl("txtPercentage"); SkuShipping order = context.SkuShippings.FirstOrDefault( p => (p.SkuId == Id) && (p.IncludeRushShipping == false) && (p.PrefId == 1)); if (order != null) { order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } else { SkuShipping item = new SkuShipping(); item.SkuId = Id; item.Cost = Convert.ToDecimal(txtCostVal.Text); item.IncludeRushShipping = false; item.PrefId = 1; context.SkuShippings.InsertOnSubmit(item); context.SubmitChanges(); } } } } } } //end if for Shipping SkuItem level if (pnlFlat.Visible) { option = ShippingOptionType.Flat; } if (cbRushShippingOption.Checked) { if (pnlRushOrderTotal.Visible) { optionRush = ShippingOptionType.TotalAmount; if (this.rptRushOrderTotal.Items.Count > 0) { using ( CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptRushOrderTotal.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } } } } } if (pnlRushOrderweight.Visible) { optionRush = ShippingOptionType.Weight; if (this.rptRushOrderWeight.Items.Count > 0) { using ( CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptRushOrderWeight.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } } } } } if (pnlRushSkuItem.Visible) { optionRush = ShippingOptionType.SkuBased; if (this.rptRushSkuItem.Items.Count > 0) { using ( CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()) ) { foreach (RepeaterItem lst in rptRushSkuItem.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text); TextBox txtCostVal = (TextBox)lst.FindControl("txtPercentage"); SkuShipping order = context.SkuShippings.FirstOrDefault( p => (p.SkuId == Id) && (p.IncludeRushShipping == true) && (p.PrefId == 1)); if (order != null) { order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } else { SkuShipping item = new SkuShipping(); item.SkuId = Id; item.Cost = Convert.ToDecimal(txtCostVal.Text); item.IncludeRushShipping = true; item.PrefId = 1; context.SkuShippings.InsertOnSubmit(item); context.SubmitChanges(); } } } } } } } if (pnlRushFlat.Visible) { optionRush = ShippingOptionType.Flat; } using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { ShippingPref Val = context.ShippingPrefs.FirstOrDefault(x => x.PrefId == DefaultSitePrefereceId); if (Val != null) { if (pnlFlat.Visible) { Val.flatShipping = Convert.ToDecimal(txtFlat.Text); } if (pnlRushFlat.Visible) { Val.RushShippingCost = Convert.ToDecimal(txtRushFlat.Text); } if (cbRushShippingOption.Checked) { Val.RushOptionId = (int)optionRush; } Val.OptionId = (int)option; Val.InCludeRushShipping = cbRushShippingOption.Checked; context.SubmitChanges(); } } // save additional charges if (this.rptShippingCharges.Items.Count > 0) { List <int> deleteList = new List <int>(); using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptShippingCharges.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int id = Convert.ToInt32(((HiddenField)lst.FindControl("hidShippingChargeId")).Value); CheckBox chkDelete = (CheckBox)lst.FindControl("chkDelete"); if (chkDelete.Checked) { deleteList.Add(id); } else { TextBox txtKey = (TextBox)lst.FindControl("txtKey"); TextBox txtCost = (TextBox)lst.FindControl("txtCost"); TextBox txtLabel = (TextBox)lst.FindControl("txtLabel"); ShippingCharge shippingCharge = context.ShippingCharges.Single(p => p.ShippingChargeId == id); shippingCharge.Key = txtKey.Text; shippingCharge.Cost = Convert.ToDecimal(txtCost.Text); shippingCharge.FriendlyLabel = txtLabel.Text; context.SubmitChanges(); } } } } if (deleteList.Count > 0) { foreach (int id in deleteList) { CSBusiness.Shipping.ShippingManager.RemoveShippingCharge(id); } } } lblCancel.Visible = false; lblSuccess.Visible = true; } //end of Save Command else { PopulateControls(); lblCancel.Visible = true; lblSuccess.Visible = false; } // Response.Redirect("Main.aspx"); }
/// <summary> /// Save Command Operation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e) { if (e.CommandName == "Save") { ShippingOptionType option = ShippingOptionType.SiteLevelPref; ShippingOptionType optionRush = ShippingOptionType.SiteLevelPref; int?stateId = null; int countryId; if (DropDownListState.SelectedItem.Value.Length > 0) { stateId = Convert.ToInt32(DropDownListState.SelectedItem.Value); } countryId = Convert.ToInt32(DropDownListCountry.SelectedItem.Value); if (PrefId == 0) //New Region Defined in the system { //Check User Creating same Custom Shipping again or not if (!ShippingDAL.IsValidShippingRegion(countryId, stateId)) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { ShippingPref item = new ShippingPref { flatShipping = (pnlFlat.Visible) ? Convert.ToDecimal(txtFlat.Text) : 0, RushShippingCost = (pnlRushFlat.Visible) ? Convert.ToDecimal(txtRushFlat.Text) : 0, RushOptionId = (int)optionRush, OptionId = (int)option, InCludeRushShipping = cbRushShippingOption.Checked, IsCustomized = true }; context.ShippingPrefs.InsertOnSubmit(item); context.SubmitChanges(); PrefId = item.PrefId; //Associate PrefId to Region Table ShippingRegion newRegion = new ShippingRegion { CountryId = countryId, StateId = stateId, PrefId = PrefId }; context.ShippingRegions.InsertOnSubmit(newRegion); context.SubmitChanges(); } } else { //fire Existing Item Message } } if (PrefId > 0) { if (pnlOrderVal.Visible) { option = ShippingOptionType.TotalAmount; if (this.rptItems.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptItems.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); if (order != null) { order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); order.PrefId = PrefId; context.SubmitChanges(); } } } } } } //end if for Shipping OrderValue if (pnlWeight.Visible) { option = ShippingOptionType.Weight; if (this.rptOrderWeight.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptOrderWeight.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); if (order != null) { order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); order.PrefId = PrefId; context.SubmitChanges(); } } } } } }//end if for Shipping OrderWeight if (pnlSkuItem.Visible) { option = ShippingOptionType.SkuBased; if (this.rptSkuItem.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptSkuItem.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text); TextBox txtCostVal = (TextBox)lst.FindControl("txtPercentage"); SkuShipping order = context.SkuShippings.FirstOrDefault(p => (p.SkuId == Id) && (p.IncludeRushShipping == false) && (p.PrefId == PrefId)); if (order != null) { order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } else { SkuShipping item = new SkuShipping(); item.SkuId = Id; item.Cost = Convert.ToDecimal(txtCostVal.Text); item.IncludeRushShipping = false; item.PrefId = PrefId; context.SkuShippings.InsertOnSubmit(item); context.SubmitChanges(); } } } } } }//end if for Shipping SkuItem level if (pnlFlat.Visible) { option = ShippingOptionType.Flat; } if (cbSitePref.Checked) { option = ShippingOptionType.SiteLevelPref; } if (cbRushShippingOption.Checked) { if (pnlRushOrderTotal.Visible) { optionRush = ShippingOptionType.TotalAmount; if (this.rptRushOrderTotal.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptRushOrderTotal.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); if (order != null) { order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); order.PrefId = PrefId; context.SubmitChanges(); } } } } } } if (pnlRushOrderweight.Visible) { optionRush = ShippingOptionType.Weight; if (this.rptRushOrderWeight.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptRushOrderWeight.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text); TextBox txtOrderVal = (TextBox)lst.FindControl("txtOrderItem"); TextBox txtCostVal = (TextBox)lst.FindControl("txtCostItem"); ShippingOrderValue order = context.ShippingOrderValues.Single(p => p.ShippingId == Id); if (order != null) { order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text); order.Cost = Convert.ToDecimal(txtCostVal.Text); order.PrefId = PrefId; context.SubmitChanges(); } } } } } } if (pnlRushSkuItem.Visible) { optionRush = ShippingOptionType.SkuBased; if (this.rptRushSkuItem.Items.Count > 0) { using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptRushSkuItem.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int Id = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text); TextBox txtCostVal = (TextBox)lst.FindControl("txtPercentage"); SkuShipping order = context.SkuShippings.FirstOrDefault(p => (p.SkuId == Id) && (p.IncludeRushShipping == true) && (p.PrefId == PrefId)); if (order != null) { order.Cost = Convert.ToDecimal(txtCostVal.Text); context.SubmitChanges(); } else { SkuShipping item = new SkuShipping(); item.SkuId = Id; item.Cost = Convert.ToDecimal(txtCostVal.Text); item.IncludeRushShipping = true; item.PrefId = PrefId; context.SkuShippings.InsertOnSubmit(item); context.SubmitChanges(); } } } } } } } if (pnlRushFlat.Visible) { optionRush = ShippingOptionType.Flat; } if (cbRushSitePref.Checked) { optionRush = ShippingOptionType.SiteLevelPref; } using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { ShippingPref Val = context.ShippingPrefs.FirstOrDefault(x => x.PrefId == PrefId); if (Val != null) { if (pnlFlat.Visible) { Val.flatShipping = Convert.ToDecimal(txtFlat.Text); } if (pnlRushFlat.Visible) { Val.RushShippingCost = Convert.ToDecimal(txtRushFlat.Text); } if (cbRushShippingOption.Checked) { Val.RushOptionId = (int)optionRush; } Val.OptionId = (int)option; Val.InCludeRushShipping = cbRushShippingOption.Checked; context.SubmitChanges(); } } }// prefId check // save additional charges if (this.rptShippingCharges.Items.Count > 0) { List <int> deleteList = new List <int>(); using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection())) { foreach (RepeaterItem lst in rptShippingCharges.Items) { if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem)) { int id = Convert.ToInt32(((HiddenField)lst.FindControl("hidShippingChargeId")).Value); CheckBox chkDelete = (CheckBox)lst.FindControl("chkDelete"); if (chkDelete.Checked) { deleteList.Add(id); } else { TextBox txtKey = (TextBox)lst.FindControl("txtKey"); TextBox txtCost = (TextBox)lst.FindControl("txtCost"); TextBox txtLabel = (TextBox)lst.FindControl("txtLabel"); ShippingCharge shippingCharge = context.ShippingCharges.Single(p => p.ShippingChargeId == id); shippingCharge.Key = txtKey.Text; shippingCharge.Cost = Convert.ToDecimal(txtCost.Text); shippingCharge.FriendlyLabel = txtLabel.Text; context.SubmitChanges(); } } } } if (deleteList.Count > 0) { foreach (int id in deleteList) { CSBusiness.Shipping.ShippingManager.RemoveShippingCharge(id); } } } }//end of save Response.Redirect("CustomShippingList.aspx"); }
private bool ManageShippingCharge(int?PK, eRepeaterOperation RepeaterOperation) { var dtShippingCharge = new DataTable(); var lstShippingChargeInsert = new List <ShippingCharge>(); var lstShippingChargeUpdate = new List <ShippingCharge>(); int CourierId = lblCourierId.zToInt().Value; if (RepeaterOperation == eRepeaterOperation.Save) { dtShippingCharge = new Query() { FirmId = lblFirmId.zToInt(), CourierId = CourierId, }.Select(eSP.qry_ShippingCharge); } else if (RepeaterOperation != eRepeaterOperation.Validate) { dtShippingCharge = new DataTable(); dtShippingCharge.Columns.Add(CS.eCourierType); dtShippingCharge.Columns.Add(CS.eZone); dtShippingCharge.Columns.Add(CS.Weight); dtShippingCharge.Columns.Add(CS.ShipCharge); dtShippingCharge.Columns.Add(CS.FirmShipCharge); } if (RepeaterOperation == eRepeaterOperation.Select) { #region Get Data From DB var dt = new Query() { FirmId = lblFirmId.zToInt(), CourierId = CourierId, }.Select(eSP.qry_ShippingCharge); foreach (DataRow dr in dt.Rows) { var drShippingCharge = dtShippingCharge.NewRow(); drShippingCharge[CS.eCourierType] = dr[CS.eCourierType].ToString(); drShippingCharge[CS.eZone] = dr[CS.eZone].ToString(); drShippingCharge[CS.Weight] = dr[CS.Weight].ToString(); drShippingCharge[CS.ShipCharge] = dr[CS.ShipCharge].ToString(); drShippingCharge[CS.FirmShipCharge] = dr[CS.FirmShipCharge].ToString(); dtShippingCharge.Rows.Add(drShippingCharge); } #endregion } else { #region Manage Data foreach (RepeaterItem Item in rptShippingCharge.Items) { var lblPK = Item.FindControl("lblPK") as Label; var txtWeight = Item.FindControl("txtWeight") as TextBox; if (RepeaterOperation == eRepeaterOperation.Remove && PK == lblPK.zToInt()) { continue; } if (RepeaterOperation == eRepeaterOperation.Save && (!txtWeight.zIsDecimal(false) || txtWeight.zToDecimal() <= 0)) { continue; } var rptZone = Item.FindControl("rptZone") as Repeater; foreach (RepeaterItem ItemZone in rptZone.Items) { var rptCourierType = ItemZone.FindControl("rptCourierType") as Repeater; foreach (RepeaterItem ItemCourierType in rptCourierType.Items) { var lblCourierTypeId = ItemCourierType.FindControl("lblCourierTypeId") as Label; var lblZoneId = ItemCourierType.FindControl("lblZoneId") as Label; var txtShipCharge = ItemCourierType.FindControl("txtShipCharge") as TextBox; var txtFirmShipCharge = ItemCourierType.FindControl("txtFirmShipCharge") as TextBox; if (RepeaterOperation == eRepeaterOperation.Add || RepeaterOperation == eRepeaterOperation.Refresh || RepeaterOperation == eRepeaterOperation.Remove) { #region Get Old Data var drShippingCharge = dtShippingCharge.NewRow(); drShippingCharge[CS.eCourierType] = lblCourierTypeId.Text; drShippingCharge[CS.eZone] = lblZoneId.Text; drShippingCharge[CS.Weight] = txtWeight.Text; drShippingCharge[CS.ShipCharge] = txtShipCharge.Text; drShippingCharge[CS.FirmShipCharge] = txtFirmShipCharge.Text; dtShippingCharge.Rows.Add(drShippingCharge); #endregion } else if (RepeaterOperation == eRepeaterOperation.Validate) { #region Validate if (txtShipCharge.zToInt() > 0 || txtFirmShipCharge.zToInt() > 0) { if (!txtWeight.zIsDecimal(false) || txtWeight.zToDecimal() <= 0) { txtWeight.Focus(); CU.ZMessage(eMsgType.Error, string.Empty, "Please Enter Weight"); return(false); } if (!txtShipCharge.zIsDecimal(false) || txtShipCharge.zToDecimal() <= 0) { txtShipCharge.Focus(); CU.ZMessage(eMsgType.Error, string.Empty, "Please Enter Courier Charge"); return(false); } if (!txtFirmShipCharge.zIsDecimal(false) || txtFirmShipCharge.zToDecimal() <= 0) { txtFirmShipCharge.Focus(); CU.ZMessage(eMsgType.Error, string.Empty, "Please Enter Firm Courier Charge"); return(false); } } #endregion } else if (RepeaterOperation == eRepeaterOperation.Save) { #region Save Data if (txtShipCharge.zToInt() > 0 || txtFirmShipCharge.zToInt() > 0) { var objShippingCharge = new ShippingCharge() { ShippingChargeId = dtShippingCharge.Rows.Count > 0 ? dtShippingCharge.Rows[0][CS.ShippingChargeId].zToInt() : (int?)null, FirmId = lblFirmId.zToInt(), CourierId = CourierId, Weight = txtWeight.zToDecimal(), eCourierType = lblCourierTypeId.zToInt(), eZone = lblZoneId.zToInt(), ShipCharge = txtShipCharge.zToInt(), FirmShipCharge = txtFirmShipCharge.zToInt() }; if (objShippingCharge.ShippingChargeId.HasValue) { dtShippingCharge.Rows.RemoveAt(0); lstShippingChargeUpdate.Add(objShippingCharge); } else { lstShippingChargeInsert.Add(objShippingCharge); } } #endregion } } } } #endregion } if (RepeaterOperation == eRepeaterOperation.Add || RepeaterOperation == eRepeaterOperation.Refresh || RepeaterOperation == eRepeaterOperation.Remove || RepeaterOperation == eRepeaterOperation.Select) { #region Manage And Bind Data if (RepeaterOperation == eRepeaterOperation.Add || dtShippingCharge.Rows.Count == 0) { var drShippingCharge = dtShippingCharge.NewRow(); dtShippingCharge.Rows.Add(drShippingCharge); } dtCourierType = CU.GetEnumDt <eCourierType>(string.Empty); dtZone = CU.GetEnumDt <eZone>(string.Empty); dtShippingChargeData = dtShippingCharge; dtShippingCharge = dtShippingCharge.DefaultView.ToTable(true, CS.Weight); rptShippingCharge.DataSource = dtShippingCharge; rptShippingCharge.DataBind(); #endregion } else if (RepeaterOperation == eRepeaterOperation.Save) { #region Save Data var lstShippingChargeDelete = new List <ShippingCharge>(); foreach (DataRow dr in dtShippingCharge.Rows) { lstShippingChargeDelete.Add(new ShippingCharge() { ShippingChargeId = dr[CS.ShippingChargeId].zToInt() }); } lstShippingChargeInsert.Insert(); lstShippingChargeUpdate.Update(); lstShippingChargeDelete.Delete(); #endregion } return(true); }
public ActionResult Complete(int ID) { try { if (Session["BrochureID"] != null) { ViewBag.BrochureID = Session["BrochureID"].ToString(); } else { return(RedirectPermanent("/")); } if (Session["studentID"] != null) { ViewBag.studentID = Session["studentID"].ToString(); } //Organization org=null; //if (Session["Organization"] != null) //{ // org = Session["Organization"] as Organization; //} if (Session["Order"] == null) { return(RedirectToActionPermanent("Index", new { ID = ViewBag.studentID })); } // Validate customer owns this order var order = Session["Order"] as Order; if (order != null) { var cart = ShoppingCart.GetCart(this.HttpContext); ViewBag.OrderList = cart.GetCartItems(); double total = cart.GetTotal(); double shippingamt = 0, freeShippingAmount = 0; ShippingCharge shipping = null; bool ISShipToSchool = cart.IsShipToSchool(); if (!ISShipToSchool) { shipping = db.ShippingCharges.Where(x => total >= x.LowerLimit && total <= x.UpperLimit).SingleOrDefault(); if (shipping != null) { shippingamt = shipping.Charge; freeShippingAmount = shipping.FreeAmount; } //foreach (ShippingCharge charge in shipping) //{ // if (total >= charge.LowerLimit && total <= charge.UpperLimit) // { // shippingamt = charge.Charge; // freeShippingAmount = charge.FreeAmount; // break; // } //} } else { var org = Session["Organization"] as Organization; if (org != null) { ViewBag.SchoolName = org.Name; } } //if (Session["Organization"] != null) //{ // var org = Session["Organization"] as Organization; // if (org.FreeShippingAmount) // { // if (total >= freeShippingAmount) // { // shippingamt = 0; // } // } //} ViewBag.ShippingAmount = shippingamt; SalesTaxCharge SalesTaxCharge = db.SalesTaxCharges.Where(x => x.Active == true).SingleOrDefault(); //ViewBag.SalesTaxCharge = SalesTaxCharge.TaxAmount.ToString(); //ViewBag.State = SalesTaxCharge.State.ToString(); //string shippingState = order.SState.ToUpper(); if (ShrdMaster.Instance.CheckState(order.SState, SalesTaxCharge.State)) { //SalesTaxCharge = db.SalesTaxCharges.Where(x => x.Active == true).SingleOrDefault(); ViewBag.SalesTaxCharge = SalesTaxCharge.TaxAmount.ToString(); ViewBag.State = SalesTaxCharge.State.ToString(); ViewBag.IsTaxChargeable = "true"; } else { ViewBag.SalesTaxCharge = SalesTaxCharge.TaxAmount.ToString(); ViewBag.State = SalesTaxCharge.State.ToString(); ViewBag.IsTaxChargeable = "false"; // ViewBag.SalesTaxCharge = "N/A"; } HttpCookie orderCookie = new HttpCookie("orderCookie"); orderCookie.Value = order.ID.ToString(); Response.Cookies.Add(orderCookie); order.FullName = order.FirstName + " " + order.LastName; return(View(order)); } else { return(RedirectToAction("ErrorView", "Customer", new { message = "some error has occured." })); } //return View() } catch (Exception ex) { //ViewBag.Error = ex.Message; return(RedirectToAction("ErrorView", "Customer", new { message = ex.Message })); } }