Esempio n. 1
0
        public bool AddProduct(string ProductName, string ProductDesc, string ProductPrice, string ProductRest, string ProductImagePath)
        {
            var newProduct = new Product();
            newProduct.ProductName = ProductName;
            newProduct.Description = ProductDesc;
            newProduct.UnitPrice = Convert.ToDouble(ProductPrice);
            newProduct.ImagePath = ProductImagePath;
            newProduct.RestaurantID = Convert.ToInt32(ProductRest);

            using (ProductContext context = new ProductContext())
            {
                context.Products.Add(newProduct);
                context.SaveChanges();
            }

            return true;
        }
Esempio n. 2
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new CampusCourier.Models.ProductContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == updateCartID && c.Product.ProductID == updateProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 myItem.Quantity = quantity;
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Esempio n. 3
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new CampusCourier.Models.ProductContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.Product.ProductID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Remove Item.
                 _db.ShoppingCartItems.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Esempio n. 4
0
        protected void RemoveProductButton_Click(object sender, EventArgs e)
        {
            using (var _db = new CampusCourier.Models.ProductContext())
            {
                int productId = Convert.ToInt16(DropDownRemoveProduct.SelectedValue);
                var myItem = (from c in _db.Products where c.ProductID == productId select c).FirstOrDefault();
                if (myItem != null)
                {
                    _db.Products.Remove(myItem);
                    _db.SaveChanges();

                    // Reload the page.
                    string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                    Response.Redirect(pageUrl + "?ProductAction=remove");
                }
                else
                {
                    LabelRemoveStatus.Text = "Unable to locate product.";
                }
            }
        }
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new ProductContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == updateCartID && c.Product.ProductID == updateProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 myItem.Quantity = quantity;
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new CampusCourier.Models.ProductContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.Product.ProductID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Remove Item.
                 _db.ShoppingCartItems.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                NVPAPICaller payPalCaller = new NVPAPICaller();

                string retMsg = "";
                string token = "";
                string PayerID = "";
                NVPCodec decoder = new NVPCodec();
                token = Session["token"].ToString();

                bool ret = payPalCaller.GetCheckoutDetails(token, ref PayerID, ref decoder, ref retMsg);
                if (ret)
                {
                    Session["payerId"] = PayerID;

                    var myOrder = new Orders();

                    myOrder.Username = User.Identity.Name;
                    myOrder.Total = Convert.ToDecimal(decoder["AMT"].ToString());

                    // Verify total payment amount as set on CheckoutStart.aspx.
                    try
                    {
                        decimal paymentAmountOnCheckout = Convert.ToDecimal(Session["payment_amt"].ToString());
                        decimal paymentAmoutFromPayPal = Convert.ToDecimal(decoder["AMT"].ToString());
                        if (paymentAmountOnCheckout != paymentAmoutFromPayPal)
                        {
                            Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                        }
                    }
                    catch (Exception)
                    {
                        Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                    }

                    // Get DB context.
                    ProductContext _db = new ProductContext();

                    // Add order to DB.
                    _db.Orders.Add(myOrder);
                    _db.SaveChanges();

                    // Get the shopping cart items and process them.
                    using (CampusCourier.Logic.ShoppingCartActions usersShoppingCart = new CampusCourier.Logic.ShoppingCartActions())
                    {
                        List<CartItem> myOrderList = usersShoppingCart.GetCartItems();

                        // Add OrderDetail information to the DB for each product purchased.
                        for (int i = 0; i < myOrderList.Count; i++)
                        {
                            // Create a new OrderDetail object.
                            var myOrderDetail = new OrderDetail();
                            myOrderDetail.OrderId = myOrder.OrderId;
                            myOrderDetail.CustName = User.Identity.Name;
                            myOrderDetail.ProductId = myOrderList[i].ProductId;
                            myOrderDetail.Quantity = myOrderList[i].Quantity;
                            myOrderDetail.UnitPrice = myOrderList[i].Product.UnitPrice;

                            // Add OrderDetail to DB.
                            _db.OrderDetails.Add(myOrderDetail);
                            _db.SaveChanges();
                        }

                        // Set OrderId. Remove this if it wont work
                        Session["currentOrderId"] = myOrder.OrderId;

                        //Adding data to orders

                        List<CartItem> ordersdatalist = usersShoppingCart.GetCartItems();
                        for (int i = 0; i < ordersdatalist.Count; i++)
                        {
                            var ordersdata = new Orders();
                            ordersdata.OrderId = myOrder.OrderId;
                            ordersdata.Quantity = ordersdatalist[i].Quantity;
                            int productid = ordersdatalist[i].ProductId;
                            ordersdata.RestName = ordersdatalist[i].Product.Restaurant.RestaurantName;

                            int location = Convert.ToInt32(ordersdatalist[i].Product.RestaurantID);

                            string Query = "SELECT LocationName from Locations WHERE LocationID ='" + location + "'";
                            string connectionstring = ConfigurationManager.ConnectionStrings["CampusCourier"].ConnectionString;
                            SqlConnection conn = new SqlConnection(connectionstring);
                            SqlCommand comm = new SqlCommand(Query, conn);
                            conn.Open();
                            SqlDataReader nwReader = comm.ExecuteReader();

                                while (nwReader.Read())
                                {
                                    ordersdata.Location = (string)nwReader["LocationName"];

                                }
                                nwReader.Close();
                                conn.Close();

                                ordersdata.Total = Convert.ToDecimal(ordersdatalist[i].Product.UnitPrice);
                                ordersdata.Status = "Waiting For Delivery";
                                _db.Orders.Add(ordersdata);
                                _db.SaveChanges();
                            }

                        // Display Order information.
                        List<Orders> orderList = new List<Orders>();
                        orderList.Add(myOrder);
                        ShipInfo.DataSource = orderList;
                        ShipInfo.DataBind();

                        // Display OrderDetails.
                        OrderItemList.DataSource = myOrderList;
                        OrderItemList.DataBind();
                        Session["userCheckoutCompleted"] = "true";
                        Response.Redirect("~/Checkout/CheckoutComplete.aspx");
                    }
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }