Exemplo n.º 1
0
        public ActionResult RemoveFromList(int?id)
        {
            db.Configuration.ProxyCreationEnabled = false;
            int          temp = Convert.ToInt32(Session["ProdOrdID"]);
            int          prod = Convert.ToInt32(id);
            ProductOrder po   = db.ProductOrders.Include(order => order.ProductOrderLines)
                                .Include(order => order.ProductOrderStatu)
                                .Where(order => order.ProductOrderID == temp)
                                .FirstOrDefault();
            ProductOrderLine pol = po.ProductOrderLines.Where(p => p.ProductID == prod).FirstOrDefault();

            po.ProductOrderLines.Remove(pol);
            db.SaveChanges();
            return(RedirectToAction("MakeClientOrder", "ProductOrder", new { id = Session["ClientID"] }));
        }
Exemplo n.º 2
0
        public ActionResult RemoveFromCart(int?id)
        {
            db.Configuration.ProxyCreationEnabled = false;
            int                 user = Convert.ToInt32(Session["UserID"]);
            Product             pm;
            HttpResponseMessage re = GlobalVariables.WebAPIClient.GetAsync("Product/" + id.ToString()).Result;// finds the product

            pm = re.Content.ReadAsAsync <Product>().Result;

            ProductOrder productorder = db.ProductOrders.Where(po => po.ProductOrderStatusID == 1)
                                        .Include(po => po.Location.Client)
                                        .Include(po => po.ProductOrderLines.Select(line => line.Product))
                                        .Where(po => po.Location.Client.UserID == user).FirstOrDefault();

            ProductOrderLine ln = productorder.ProductOrderLines.Where(pl => pl.ProductID == id).FirstOrDefault();

            productorder.ProductOrderLines.Remove(ln);
            db.SaveChanges();

            return(RedirectToAction("Checkout", "ProductOrder", new { id = productorder.ProductOrderID }));
        }
Exemplo n.º 3
0
        public ActionResult AddProduct(int Product, int Quantity = 0)
        {
            if (Quantity < 1)
            {
                TempData["ErrorMessage"] = "Connot have a quantity less than 1";
                return(RedirectToAction("MakeClientOrder", "ProductOrder", new { id = Session["ClientID"] }));
            }
            bool inList = false;

            db.Configuration.ProxyCreationEnabled = false;
            int          temp = Convert.ToInt32(Session["ProdOrdID"]);
            ProductOrder po   = db.ProductOrders.Include(order => order.ProductOrderLines)
                                .Include(order => order.ProductOrderStatu)
                                .Where(order => order.ProductOrderID == temp)
                                .FirstOrDefault();

            foreach (ProductOrderLine pol in po.ProductOrderLines)
            {
                if (pol.ProductID == Product)
                {
                    inList = true;
                    pol.QuantityOrdered += Quantity;
                    break;
                }
            }
            if (!inList)
            {
                ProductOrderLine pol = new ProductOrderLine();
                pol.ProductID         = Product;
                pol.QuantityOrdered   = Quantity;
                pol.QuantityDelivered = 0;
                po.ProductOrderLines.Add(pol);
            }
            db.SaveChanges();
            return(RedirectToAction("MakeClientOrder", "ProductOrder", new { id = Session["ClientID"] }));
        }
Exemplo n.º 4
0
        public ActionResult AddProductToCart(int?id)
        {
            if (Session["UserID"] == null)
            {
                TempData["message"] = "Please login to place an order order";
                return(RedirectToAction("Index", "Login"));
            }
            int user = Convert.ToInt32(Session["UserID"]);

            db.Configuration.ProxyCreationEnabled = false;
            mvcProductModel     pm;
            HttpResponseMessage re = GlobalVariables.WebAPIClient.GetAsync("Product/" + id.ToString()).Result;// finds the product

            pm = re.Content.ReadAsAsync <mvcProductModel>().Result;
            ProductOrder productorder = db.ProductOrders.Where(po => po.ProductOrderStatusID == 1)
                                        .Include(po => po.Location)
                                        .Include(po => po.Location.Client)
                                        .Include(po => po.ProductOrderLines.Select(line => line.Product))
                                        .Where(po => po.Location.Client.UserID == user)
                                        .FirstOrDefault();

            if (productorder == null)//if no order started
            {
                ProductOrderLine pl = new ProductOrderLine();
                productorder         = new ProductOrder();
                pl.ProductID         = pm.ProductID;
                pl.QuantityOrdered   = 1;
                pl.QuantityDelivered = 0;
                productorder.ProductOrderStatusID = 1;
                productorder.LocationID           = db.Locations.Where(l => l.Client.UserID == user)
                                                    .Select(l => l.LocationID).FirstOrDefault();
                productorder.Client_ID = db.Clients.Where(c => c.UserID == user)
                                         .Select(c => c.ClientID).FirstOrDefault();
                db.ProductOrders.Add(productorder);
                db.SaveChanges();
                List <int> orderIDs = db.ProductOrders.Where(po => po.ProductOrderStatusID == 1).Select(po => po.ProductOrderID).ToList();
                pl.ProductOrderID = orderIDs.Last();
                db.ProductOrderLines.Add(pl);
                db.SaveChanges();
            }
            else//if order started (in cart)
            {
                bool inCart = false;
                foreach (ProductOrderLine line in productorder.ProductOrderLines)
                {
                    if (line.ProductID == pm.ProductID)
                    {
                        inCart = true;
                        line.QuantityOrdered += 1;
                        db.SaveChanges();
                        break;
                    }
                }
                if (!inCart)
                {
                    ProductOrderLine tmp = new ProductOrderLine();
                    tmp.ProductID         = pm.ProductID;
                    tmp.QuantityOrdered   = 1;
                    tmp.QuantityDelivered = 0;
                    tmp.ProductOrderID    = productorder.ProductOrderID;
                    productorder.ProductOrderLines.Add(tmp);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Checkout", "ProductOrder", new { id = productorder.ProductOrderID }));
        }