Example #1
0
        public ActionResult BuyProduct(Product p)
        {
            ProductOfUserDal dal = new ProductOfUserDal();
            ProductsOfUser   pou = new ProductsOfUser(main_user, p);

            dal.ProductsOfUser.Add(pou);
            dal.SaveChanges();
            Thread.Sleep(2000);
            return(Json(new ProductDal().Products.ToList <Product>(), JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public ActionResult DeleteProductFromUserByJson(Product p)
        {
            ProductOfUserDal dal             = new ProductOfUserDal();
            ProductsOfUser   productToRemove = dal.ProductsOfUser.FirstOrDefault(x => x.productKey.Equals(p.IdProduct) && x.userKey.Equals(main_user.Email));

            dal.ProductsOfUser.Remove(productToRemove);
            dal.SaveChanges();

            ProductDal dalPro       = new ProductDal();
            List <int> productsKeys = (from x in dal.ProductsOfUser
                                       select x.productKey).ToList <int>();

            List <Product> products = (from x in dalPro.Products
                                       where productsKeys.Contains(x.IdProduct)
                                       select x).ToList <Product>();

            Thread.Sleep(2000);
            return(Json(products, JsonRequestBehavior.AllowGet));
        }