Пример #1
0
        public ActionResult Products_Destroy([DataSourceRequest] DataSourceRequest request, ProductTable productTable)
        {
            if (ModelState.IsValid)
            {
                using (var db = new _DatabseContextShop())
                {
                    var entity = new ProductTable
                    {
                        Id           = productTable.Id,
                        ProductName  = productTable.ProductName,
                        Description  = productTable.Description,
                        UnitPrice    = productTable.UnitPrice,
                        UnitsInStock = productTable.UnitsInStock,
                        UnitsOnOrder = productTable.UnitsOnOrder,
                        Discontinued = productTable.Discontinued,
                        LastSupply   = productTable.LastSupply
                    };

                    db.Products.Attach(entity);
                    db.Products.Remove(entity);
                    db.SaveChanges();
                }
            }

            return(Json(new[] { productTable }.ToDataSourceResult(request, ModelState)));
        }
Пример #2
0
        public JsonResult QuanityChange(int type, int pId)
        {
            using (var db = new _DatabseContextShop())
            {
                ShoppingCartTable product = db.ShoppingCartDatas.FirstOrDefault(p => p.PID == pId);
                if (product == null)
                {
                    return(Json(new { d = "0" }));
                }

                ProductTable actualProduct = db.Products.FirstOrDefault(p => p.Id == pId);
                int?         quantity;
                // if type 0, decrease quantity
                // if type 1, increase quanity
                switch (type)
                {
                case 0:
                    product.Quantity--;
                    actualProduct.UnitsInStock++;
                    break;

                case 1:
                    product.Quantity++;
                    actualProduct.UnitsInStock--;
                    break;

                case -1:
                    actualProduct.UnitsInStock += product.Quantity;
                    product.Quantity            = 0;
                    break;

                default:
                    return(Json(new { d = "0" }));
                }

                if (product.Quantity == 0)
                {
                    db.ShoppingCartDatas.Remove(product);
                    quantity = 0;
                }
                else
                {
                    quantity = product.Quantity;
                }

                db.SaveChanges();
                return(Json(new { d = quantity }));
            }
        }
Пример #3
0
        public static void Add(ProductData product, _DatabseContextShop db)
        {
            var entity = new ProductTable();

            entity.ProductName  = product.ProductName;
            entity.UnitPrice    = product.UnitPrice;
            entity.Description  = product.Description;
            entity.UnitsInStock = (short)product.UnitsInStock;
            entity.Discontinued = product.Discontinued;
            entity.Id           = product.ProductID;
            entity.LastSupply   = DateTime.Now;
            entity.UnitsOnOrder = product.UnitsOnOrder;



            db.Products.Add(entity);
            db.SaveChanges();
        }