Beispiel #1
0
        public async Task <ActionResult> Product()
        {
            GDFService _svc = new GDFService();
            var        ret  = await _svc.LoginAsync(Session["user"].ToString(), Session["pass"].ToString());

            if (!ret)
            {
                return(null);
            }
            //var id = Convert.ToInt32(Session["id"]);
            var proj = await _svc.GetProjectAsync(Convert.ToInt32(Session["id"]));

            //Project proj = new Project(Session["name"].ToString());

            if (proj == null)
            {
                ViewBag("There is no data in the system!");
            }
            else
            {
                //assign list of Part to proj variable
                List <ProductionProcess> productionProcesses = new List <ProductionProcess>(proj.ProductionProcesses);


                List <Product_View> product_Views = new List <Product_View>();

                foreach (var p in productionProcesses)
                {
                    //Define Process Object

                    List <Product> products = new List <Product>(p.Products);
                    foreach (var k in products)
                    {
                        Product_View product = new Product_View();
                        product.Name = k.Name;
                        product.Desc = k.Desc;


                        product_Views.Add(product);
                    }
                }//end of foreach

                return(View(product_Views));
            } //end of else
            return(null);
        }     //end of project info
        public async Task <ActionResult> Product(string name)
        {
            GDFService _svc = new GDFService();
            var        ret  = await _svc.LoginAsync(Session["user"].ToString(), Session["pass"].ToString());

            if (!ret)
            {
                return(null);
            }

            var proj = await _svc.GetProjectAsync(Convert.ToInt32(Session["id"]));



            if (proj == null)
            {
                ViewBag("There is no data in the system!");
            }
            else
            {
                List <StationActivity> stationActivities = new List <StationActivity>(proj.StationActivities);

                StationActivity stationActivity = new StationActivity();

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

                List <Product_View> product_Views = new List <Product_View>();

                List <StationActivity_View> stationActivities_Views = new List <StationActivity_View>();
                StationActivity_View        stationActivity_View    = new StationActivity_View();

                foreach (var p in stationActivities)
                {
                    Product_View product = new Product_View();

                    product.Name = p.Product.Name;
                    product.Desc = p.Product.Desc;
                    product_Views.Add(product);
                }//end of foreach

                return(View(product_Views));
            }//end of else

            return(null);
        }//end of project info
        public ActionResult Index()
        {
            //Slide//
            List <Slide> slide = new List <Slide>();

            slide             = (from sl in db.Slides select sl).OrderByDescending(x => x.id).ToList();
            ViewBag.listSlide = slide;
            //Danh mục//
            List <Category> Categories = new List <Category>();

            Categories             = (from cate in db.Categories select cate).ToList();
            ViewBag.listCategories = Categories;

            //Hãng//
            List <Brand> Brands = new List <Brand>();

            Brands             = (from brand in db.Brands select brand).ToList();
            ViewBag.listBrands = Brands;

            //yêu thích//
            List <Product> Feature = new List <Product>();

            Feature             = (from product in db.Products where product.favorite == 1 && product.star >= 4 && product.cate_id >= 2 select product).ToList();
            ViewBag.listFeature = Feature;

            //hàng giảm giá//
            List <Product> Sales = new List <Product>();

            Sales            = (from product in db.Products where product.sale > 10 && product.star >= 4 select product).ToList();
            ViewBag.listSale = Sales.Take(10);

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

            SaleAccess             = (from product in db.Products where product.sale > 0 && product.star >= 4 && product.cate_id == 4 select product).ToList();
            ViewBag.listSaleAccess = SaleAccess.Take(12);

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

            SaleLaptop             = (from product in db.Products where product.sale > 10 && product.star >= 4 && product.cate_id == 1 select product).ToList();
            ViewBag.listSaleLaptop = SaleLaptop.Take(12);

            //Hàng mới/
            List <Product> News = new List <Product>();

            News            = (from product in db.Products where product._new == 1  select product).ToList();
            ViewBag.listNew = News.Take(8);

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

            Stars            = (from product in db.Products where product.star >= 4 select product).ToList();
            ViewBag.listStar = Stars.Take(16);

            //Phụ kiện//
            List <Product> Access = new List <Product>();

            Access             = (from product in db.Products where product.star >= 4 && product.cate_id == 4 select product).ToList();
            ViewBag.listAccess = Access.Take(16);

            //Lap top//
            List <Product> Laptop = new List <Product>();

            Laptop             = (from product in db.Products where product.star >= 4 && product.cate_id == 1 select product).ToList();
            ViewBag.listLaptop = Laptop.Take(16);

            //Đánh giá//
            List <Product_View> review = new List <Product_View>();
            var Review = db.Views.Join(db.Products, v => v.product_id, p => p.id, (v, p) => new
            {
                id      = p.id,
                name    = v.name,
                comment = v.comment,
                image   = p.image,
                vote    = v.vote
            }).ToList();

            foreach (var item in Review)
            {
                Product_View newItem = new Product_View()
                {
                    ID         = item.id,
                    Name       = item.name,
                    Dicription = item.comment,
                    Image      = item.image,
                    Vote       = item.vote
                };

                review.Add(newItem);
            }

            ViewBag.listReview = review.OrderByDescending(x => x.ID).ToList();

            //Sản phẩm đề cử//
            Random         r      = new Random();
            List <Product> NewHot = new List <Product>();

            NewHot             = (from product in db.Products where product._new == 1 && product.star == 5 select product).ToList();
            ViewBag.listNewHot = NewHot.OrderBy(product => r.Next()).Take(1);

            //Sản phẩm đề cử//
            List <Product> Recent = new List <Product>();

            Recent             = (from product in db.Products where product._new == 1 && product.star == 5  select product).ToList();
            ViewBag.listRecent = Recent.Take(8);

            //Giỏ hàng//
            List <CartItem> giohang = Session["giohang"] as List <CartItem>;

            ViewBag.Cart = giohang;

            //Session User//
            List <UserItem> UserSession = Session["UserSession"] as List <UserItem>;

            ViewBag.listUserSession = UserSession;

            return(View());
        }