Exemplo n.º 1
0
        public string ConfirmOrder(string UserID)
        {
            DetailsViewModel custDetails = new DetailsViewModel();
            custDetails = (DetailsViewModel)Session["MyOrder"];
            List<CartItem> cart = (List<CartItem>)Session["cart"];

            List<MyOrder> orders = new List<MyOrder>();

            for (int i = 0; i < cart.Count; i++)
            {
                MyOrder order = new MyOrder();
                order.ShippingAddress = custDetails.Address;
                order.City = custDetails.City;
                order.State = custDetails.State;
                order.Pincode = custDetails.Pincode;
                order.UserID = UserID;
                order.ApparelID = cart[i].Apparel.ApparelID;
                order.ProductName = cart[i].Apparel.ApparelName;
                order.SizeOfApparel = cart[i].Apparel.ApparelSize;
                order.Quantity = cart[i].Quantity;
                order.TotalAmount = cart[i].Quantity * (cart[i].Apparel.ApparelCost - (cart[i].Apparel.ApparelCost * cart[i].Apparel.ApparelDiscount)/100);
                orders.Add(order);
            }
            string status = bllObj.InsertOrderDetails(orders);
            if (!status.Equals("false"))
                Session["cart"] = null;
            return status;
        }
Exemplo n.º 2
0
        public List<MyOrder> GetOrderDetails(string UserID)
        {
            List<MyOrder> orders = new List<MyOrder>();
            string conStr = ConfigurationManager.ConnectionStrings["FashionableMeDB"].ConnectionString;
            SqlConnection conn = new SqlConnection(conStr);
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("SELECT * FROM CustomerOrders WHERE CustomerID=@UserID", conn);
                cmd.Parameters.AddWithValue("UserID", UserID);

                var reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while(reader.Read())
                    {
                        MyOrder order = new MyOrder();

                        order.TransactionID = reader.GetString(reader.GetOrdinal("TransactionID"));
                        order.UserID = reader.GetString(reader.GetOrdinal("CustomerID")).ToString();
                        order.ProductName = reader.GetString(reader.GetOrdinal("ProductName"));
                        order.SizeOfApparel = reader.GetString(reader.GetOrdinal("SizeOfApparel"));
                        order.Quantity = reader.GetInt32(reader.GetOrdinal("Quantity"));
                        order.TotalAmount = reader.GetDecimal(reader.GetOrdinal("TotalAmount"));
                        order.ShippingAddress = reader.GetString(reader.GetOrdinal("ShippingAddress"));
                        order.City = reader.GetString(reader.GetOrdinal("City"));
                        order.State = reader.GetString(reader.GetOrdinal("State"));
                        order.Pincode = reader.GetInt64(reader.GetOrdinal("Pincode")).ToString() ;
                        order.DateOfPurchase = reader.GetDateTime(reader.GetOrdinal("DateOfPurchase"));

                        orders.Add(order);
                    }
                }
            }
            catch (Exception exc)
            {
                HttpContext.Current.Session["ErrorMessage"] = exc.Message;
            }
            conn.Close();
            return orders;
        }
Exemplo n.º 3
0
        public string InsertOrderDetails(List<MyOrder> orders)
        {
            string status = "false";
            HttpContext.Current.Session["status"] = "DefaultMessage";
            string conStr = ConfigurationManager.ConnectionStrings["FashionableMeDB"].ConnectionString;
            SqlConnection conn = new SqlConnection(conStr);
            try
            {
                conn.Open();

                MyOrder order = new MyOrder();
                DateTime dateOfPurchase = DateTime.Now;
                Random generator = new Random();
                String transactionID = generator.Next(0, 1000000).ToString("D6");
                for (int i = 0; i < orders.Count; i++)
                {
                    SqlCommand cmd = new SqlCommand("INSERT INTO CustomerOrders values (@TransactionID, @CustomerID, @ProductName, @SizeOfApparel, @Quantity, @TotalAmount, @ShippingAddress, @City, @State, @Pincode, @DateOfPurchase )", conn);
                    order = orders[i];
                    if (updatePurchasedQuantity(order.ApparelID, order.SizeOfApparel, order.Quantity))
                    {
                    cmd.Parameters.AddWithValue("TransactionID", transactionID);
                    cmd.Parameters.AddWithValue("CustomerID", order.UserID);
                    cmd.Parameters.AddWithValue("ProductName", order.ProductName);
                    cmd.Parameters.AddWithValue("SizeOfApparel", order.SizeOfApparel);
                    cmd.Parameters.AddWithValue("Quantity", order.Quantity);
                    cmd.Parameters.AddWithValue("TotalAmount", order.TotalAmount);
                    cmd.Parameters.AddWithValue("ShippingAddress", order.ShippingAddress);
                    cmd.Parameters.AddWithValue("City", order.City);
                    cmd.Parameters.AddWithValue("State", order.State);
                    cmd.Parameters.AddWithValue("Pincode", order.Pincode);
                    cmd.Parameters.AddWithValue("DateOfPurchase", dateOfPurchase);

                    int rslt = cmd.ExecuteNonQuery();
                        status = transactionID;
                    }
                    else
                    {
                        status = "false";
                        break;
                    }
                }

            }
            catch (Exception exc)
            {
                HttpContext.Current.Session["ErrorMessage"] = exc.Message;
            }
            conn.Close();
            return status;
        }