public int InsertCart(Ent_OrderDetail entGuest, SafeTransaction trans) { int dataResult = 0; try { Dal_Order dal = new Dal_Order(); dataResult = dal.InsertCart(entGuest, trans); return(dataResult); } catch { return(0); } }
public int UpdateCart(List <Ent_Product> CartList) { float total = 0; List <Ent_OrderDetail> item = new List <Ent_OrderDetail>(); for (int i = 0; i < CartList.Count; i++) { item.Add(new Ent_OrderDetail() { Product_ID = CartList[i].Product_ID, Product_Name = CartList[i].Product_Name, Quantity = CartList[i].Quantity, Product_Price = CartList[i].Product_Price, Product_Image = CartList[i].Product_Image, Product_Total = CartList[i].Quantity * CartList[i].Product_Price, }); HttpCookie Guest_ID = Request.Cookies["Guest_ID"]; string GuestID = Guest_ID != null?Guest_ID.Value.Split('=')[1] : ""; if (!string.IsNullOrEmpty(GuestID)) { Ent_OrderDetail entP = new Ent_OrderDetail(); entP.Cart_ID = 1; entP.Product_ID = CartList[i].Product_ID; entP.Quantity = CartList[i].Quantity; entP.Guest_ID = Convert.ToInt32(GuestID); SafeTransaction trans = new SafeTransaction(); int result = balOrder.InsertCart(entP, trans); if (result > 0) { trans.Commit(); } else { trans.Rollback(); } } total = total + (CartList[i].Quantity * CartList[i].Product_Price); Session["Cart"] = item; item = (List <Ent_OrderDetail>)Session["Cart"]; } Session["SubTotal"] = Session["Total"] = total; return(1); }
public int InsertCart(Ent_OrderDetail ent, SafeTransaction trans) { int dataresult = 0; try { if (con.State == ConnectionState.Closed) { con.Open(); } using (SqlCommand cmd = new SqlCommand("EC_InsertCart", trans.DatabaseConnection, trans.Transaction)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@Cart_ID", ent.Cart_ID)); cmd.Parameters.Add(new SqlParameter("@Product_ID", ent.Product_ID)); cmd.Parameters.Add(new SqlParameter("@Quantity", ent.Quantity)); cmd.Parameters.Add(new SqlParameter("@Guest_ID", ent.Guest_ID)); try { dataresult = Convert.ToInt32(cmd.ExecuteScalar()); if (dataresult > 0) { cmd.Dispose(); } } catch (Exception ex) { dataresult = -2; } } } catch (Exception e) { dataresult = -2; } finally { con.Close(); } return(dataresult); }
public List <Ent_OrderDetail> SelectCart(int guestID) { List <Ent_OrderDetail> result = new List <Ent_OrderDetail>(); Ent_OrderDetail ent = new Ent_OrderDetail(); try { using (SqlCommand cmd = new SqlCommand("EC_SelectCart", con)) { if (con.State == ConnectionState.Closed) { con.Open(); } cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@Guest_ID", guestID)); IDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { ent = new Ent_OrderDetail(); ent.Product_ID = Convert.ToInt32(dr["Product_ID"]); ent.Product_Name = Convert.ToString(dr["Product_Name"]); ent.Quantity = Convert.ToInt32(dr["Quantity"]); ent.Product_Price = float.Parse(dr["Product_Price"].ToString()); ent.Product_Total = float.Parse(dr["Product_Total"].ToString()); ent.Product_Image = Convert.ToString(dr["Product_Image"]); result.Add(ent); } } } catch (Exception ex) { InsertException(ex.Message, "SelectCart", guestID); } finally { con.Close(); } return(result); }
public List <Ent_OrderDetail> SelectOrderDetails(int OrderId) { List <Ent_OrderDetail> result = new List <Ent_OrderDetail>(); Ent_OrderDetail ent = new Ent_OrderDetail(); try { using (SqlCommand cmd = new SqlCommand("EC_SelectOrderDetails", con)) { if (con.State == ConnectionState.Closed) { con.Open(); } cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@Order_ID", OrderId)); IDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { ent = new Ent_OrderDetail(); ent.OrderDetail_ID = Convert.ToInt32(dr["OrderDetail_ID"]); ent.Order_ID = Convert.ToInt32(dr["Order_ID"]); ent.Product_ID = Convert.ToInt32(dr["Product_ID"]); ent.Product_Total = float.Parse(dr["Product_Total"].ToString()); ent.Product_Price = float.Parse(dr["Product_Price"].ToString()); ent.Quantity = Convert.ToInt32(dr["Quantity"]); ent.Product_Image = Convert.ToString(dr["Product_Image"]); ent.Product_Name = Convert.ToString(dr["Product_Name"]); ent.entOrder.Order_Shipping = float.Parse(dr["Order_Shipping"].ToString()); ent.entOrder.Order_Total = float.Parse(dr["Order_Total"].ToString()); ent.entOrder.Order_SubTotal = float.Parse(dr["Order_SubTotal"].ToString()); ent.entOrder.Is_Active = Convert.ToInt32(dr["Is_Active"]); if (dr["Received_Date"].ToString() == "") { ent.entOrder.Received_Date = null; } else { ent.entOrder.Received_Date = dr["Received_Date"].ToString(); } if (dr["Shipped_Date"].ToString() == "") { ent.entOrder.Shipped_Date = null; } else { ent.entOrder.Shipped_Date = dr["Shipped_Date"].ToString(); } if (dr["Delivered_Date"].ToString() == "") { ent.entOrder.Delivered_Date = null; } else { ent.entOrder.Delivered_Date = dr["Delivered_Date"].ToString(); } if (dr["Cancel_Date"].ToString() == "") { ent.entOrder.Cancel_Date = null; } else { ent.entOrder.Cancel_Date = dr["Cancel_Date"].ToString(); } if (dr["Return_Date"].ToString() == "") { ent.entOrder.Return_Date = null; } else { ent.entOrder.Return_Date = dr["Return_Date"].ToString(); } result.Add(ent); } } } catch (Exception ex) { InsertException(ex.Message, "SelectOrderDetails", OrderId); } finally { con.Close(); } return(result); }
// GET: Order public int AddToCart(int Product_ID) { Ent_Product ent = new Ent_Product(); ent = balProduct.SelectProduct(Product_ID); HttpCookie Guest_ID = Request.Cookies["Guest_ID"]; int GuestID = Guest_ID != null?Convert.ToInt32(Guest_ID.Value.Split('=')[1]) : 0; int qty = 1; int cartid = 0; if (Session["Cart"] == null) { List <Ent_OrderDetail> item = new List <Ent_OrderDetail>(); item.Add(new Ent_OrderDetail() { Product_ID = Product_ID, Product_Name = ent.Product_Name, Quantity = 1, Product_Price = ent.Product_Price - ent.Product_Discount, Product_Image = ent.Product_Image, Product_Total = ent.Product_Price - ent.Product_Discount, }); Session["Cart"] = item; Session["SubTotal"] = ent.Product_Price - ent.Product_Discount; Session["Total"] = ent.Product_Price - ent.Product_Discount; } else { List <Ent_OrderDetail> item = (List <Ent_OrderDetail>)Session["Cart"]; bool has = item.Any(x => x.Product_ID == Product_ID); if (has == false) { item.Add(new Ent_OrderDetail() { Product_ID = Product_ID, Product_Name = ent.Product_Name, Quantity = 1, Product_Price = ent.Product_Price - ent.Product_Discount, Product_Image = ent.Product_Image, Product_Total = ent.Product_Price - ent.Product_Discount, }); } else { item.Where(w => w.Product_ID == Product_ID).ToList().ForEach(i => { i.Quantity = i.Quantity + 1; i.Product_Total = ((i.Quantity) * i.Product_Price); }); qty = item.Where(l => l.Product_ID == Product_ID).FirstOrDefault().Quantity; cartid = 1; } Session["Cart"] = item; Session["SubTotal"] = Convert.ToInt32(Session["SubTotal"]) + (ent.Product_Price - ent.Product_Discount); Session["Total"] = Convert.ToInt32(Session["Total"]) + (ent.Product_Price - ent.Product_Discount); } if (GuestID != 0) { Ent_OrderDetail entP = new Ent_OrderDetail(); entP.Cart_ID = cartid; entP.Product_ID = Product_ID; entP.Quantity = qty; entP.Guest_ID = Convert.ToInt32(GuestID); SafeTransaction trans = new SafeTransaction(); int result = balOrder.InsertCart(entP, trans); if (result > 0) { trans.Commit(); } else { trans.Rollback(); } } return(1); }