コード例 #1
0
ファイル: ManagerController.cs プロジェクト: hdriel/MVC_Store
        public ActionResult SubmitUpdate(VMProductAndProducts pps)
        {
            if (ModelState.IsValid)
            {
                Product        p  = pps.product;
                List <Product> ps = pps.products;
                Product        fromDB;
                ProductDal     dal = new ProductDal();
                //fromDB = dal.Products.FirstOrDefault(x => x.IdProduct.Equals(pps.product.IdProduct));
                List <Product> products = (from x in dal.Products
                                           where x.IdProduct.Equals(pps.product.IdProduct)
                                           select x).ToList <Product>();


                if (products != null && products.Count() == 1)
                {
                    fromDB = products.ElementAt(0);
                    fromDB.cloneDetail(pps.product);
                }
                try
                {
                    dal.SaveChanges();
                    HistoricalProductDal dalHistori = new HistoricalProductDal();
                    Product fromDBHisrori           = dalHistori.Products.FirstOrDefault(x => x.IdProduct.Equals(pps.product.IdProduct));
                    dalHistori.Products.Remove(fromDBHisrori);
                    dalHistori.Products.Add(pps.product);
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(View("UpdateProduct", pps));
                }
                return(View("Actions", new VMUserAndProducrs(manager)));
            }
            return(View("UpdateProduct", pps));
        }
コード例 #2
0
        public ActionResult myOrdersAction()
        {
            HistoricalProductDal dalPro       = new HistoricalProductDal();
            ProductOfUserDal     dalProOfUser = new ProductOfUserDal();

            List <int> productsKeys = (from x in dalProOfUser.ProductsOfUser
                                       select x.productKey).ToList <int>();

            List <Product> products = new List <Product>();

            for (int i = 0; i < productsKeys.Count(); i++)
            {
                int     key       = productsKeys.ElementAt(i);
                Product proofuser = dalPro.Products.FirstOrDefault(x => x.IdProduct.Equals(key));
                products.Add(proofuser);
            }

            return(View("myOrdersAction", new VMUserAndProducrs(main_user, products)));
        }
コード例 #3
0
        public ActionResult GetMyProductsOrdersByJson()
        {
            HistoricalProductDal dalPro       = new HistoricalProductDal();
            ProductOfUserDal     dalProOfUser = new ProductOfUserDal();

            List <int> productsKeys = (from x in dalProOfUser.ProductsOfUser
                                       select x.productKey).ToList <int>();

            List <Product> products = new List <Product>();

            for (int i = 0; i < productsKeys.Count(); i++)
            {
                int     key       = productsKeys.ElementAt(i);
                Product proofuser = dalPro.Products.FirstOrDefault(x => x.IdProduct.Equals(key));
                products.Add(proofuser);
            }
            Thread.Sleep(2000);
            return(Json(products, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
ファイル: ManagerController.cs プロジェクト: hdriel/MVC_Store
        public ActionResult SubmitAdd(VM_UserAndProduct_help up)
        {
            Product p = up.product;

            if (ModelState.IsValid)
            {
                Product product = new Product(p, true);

                ProductDal dal = new ProductDal();
                dal.Products.Add(p);
                dal.SaveChanges();

                HistoricalProductDal dalHistori = new HistoricalProductDal();
                dalHistori.Products.Add(p);
                dalHistori.SaveChanges();

                return(View("Actions", new VMUserAndProducrs(manager)));
            }
            else
            {
                return(View("AddNewProduct", p));
            }
        }