コード例 #1
0
ファイル: AdminController.cs プロジェクト: unitx/ASP.NET
        public ActionResult SubmitProductsValues(ProductModel productModel)
        {
            //! Pulling DATA from db using DbContext
            var proDAL = new ProductDAL();

            //! Loop through model.ProductsCollection 
            foreach (var p in productModel.ProductsCollection)
            {
                //! Matching the current product
                var query = proDAL.Products.FirstOrDefault(q => q.Id == p.Id);

                if (query != null)
                {
                    if (p.pExist != true)
                    {
                        /*
                         * pExist it's an Indicator about the product lifetime.
                         * */
                        query.Quantity = p.Quantity;
                        proDAL.SaveChanges();
                    }
                    else
                    {
                        //! pExist True; means it was mark to be removed
                        query.pExist = false;
                        proDAL.Products.Remove(query);
                        proDAL.SaveChanges();
                    }
                }
            }
            //! All-set redirecting view.
            return View("SubmitProductsValues");
        }
コード例 #2
0
ファイル: AdminController.cs プロジェクト: unitx/ASP.NET
        public ActionResult EditProducts()
        {

            //! Pulling DATA from db using DbContext
            var proDAL = new ProductDAL();
            List<Products> pl = proDAL.Products.ToList<Products>();

            ProductModel productModel = new ProductModel();
            productModel.ProductsCollection = new List<Products>();
            productModel.ProductsCollection = pl;

            return View("EditProducts", productModel);
        }