コード例 #1
0
        public ActionResult Index(int page = 1)
        {
            try
            {
                int pagesize = 5;
                List <ProductModel> listofProd;
                int count;

                using (var Context = new ContextClass())
                {
                    listofProd = Context.Products.Include("Category").OrderBy(p => p.ProductId).Skip((page - 1) * pagesize).Take(pagesize).ToList();
                    count      = Context.Products.Count();
                }

                var productVM = new productViewModel
                {
                    listofProducts    = listofProd,
                    TotalRecordsCount = count,
                    PageNumber        = page,
                    pagesize          = pagesize
                };
                return(View(productVM));
            }
            catch (Exception)
            {
                return(View("Error"));
            }
        }
コード例 #2
0
ファイル: ProductController.cs プロジェクト: alisrk/MvcEgitim
        public async Task <IActionResult> Addproduct(productViewModel model1)
        {
            var wwwImages = Path.Combine(_environment.WebRootPath, @"Images");

            var filePath = Path.Combine(x, model1.File.FileName);

            if (model1.File.Length > 0)
            {
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await model1.File.CopyToAsync(stream);

                    model1.product.imagePath = model1.File.FileName;
                }
            }



            //if (model1.File.Length > 0)
            //{
            //    var filePath = Path.Combine(_environment.WebRootPath, @"Images");
            //   // var x = Path.Combine(Directory.GetCurrentDirectory(), @"Images");
            //    using (var stream = new FileStream(filePath, FileMode.Create))
            //    {
            //        await model1.File.CopyToAsync(stream);
            //        model1.product.imagePath = model1.File.FileName;
            //    }
            //}

            modelYeni.addproductFunc(model1.product);


            return(RedirectToAction("listproduct"));
        }
コード例 #3
0
ファイル: cbkalaController.cs プロジェクト: yar1399/test1
        public async Task <IActionResult> Product(int?id = 0)
        {
            if (id == 0)
            {
                return(Redirect("/error/Index/106769"));
            }

            productViewModel productView = new productViewModel();

            productView.product = _context.Products

                                  .Include(p => p.IdmenuNavigation)
                                  .Where(p => p.Id == id).FirstOrDefault();

            if (productView.product == null)
            {
                return(Redirect("/error/Index/106769"));
            }

            productView.postdatas = await _context.Productdata.Where(pd => pd.Idproduct == id).ToListAsync();

            productView.procolor = await _context.Productcolors.Include(p => p.IdcolorNavigation).Where(pd => pd.Idproduct == productView.product.Id).ToListAsync();

            productView.productinfo = await _context.Productinfos.Include(p => p.IdproductmenuinfoNavigation).Where(pd => pd.Idproduct == productView.product.Id).ToListAsync();

            return(View(productView));
        }
コード例 #4
0
        public ActionResult Add(productViewModel newItem)
        {
            if (Session["out"] == null)
            {
                Session["out"] = new List <ItemOrder>();
            }

            var alreadyOrderedItemIndex = 0;
            var alreadyHasItemType      = false;

            try
            {
                var currentOrders = Session["out"] as List <ItemOrder>;
                if (currentOrders != null)
                {
                    for (var i = 0; i < currentOrders.Count; i++)
                    {
                        if (((List <ItemOrder>)Session["out"])[i].productID == newItem.productID)
                        {
                            alreadyHasItemType      = true;
                            alreadyOrderedItemIndex = i;
                            break;
                        }
                    }

                    if (alreadyHasItemType)
                    {
                        ((List <ItemOrder>)Session["out"])[alreadyOrderedItemIndex].quantity++;
                    }
                    else
                    {
                        var itemOrder = new ItemOrder
                        {
                            productName  = newItem.productName,
                            productID    = newItem.productID,
                            productPrice = newItem.productPrice,
                            quantity     = 1
                        };
                        (Session["out"] as List <ItemOrder>)?.Add(itemOrder);
                        //  var c = itemOrder.quantity.ToInteger(int.MaxValue);
                    }

                    ViewBag.cart = ((List <ItemOrder>)Session["out"]).Count;

                    Session["count"] = Convert.ToInt32(Session["count"]) + 1;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw e;
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #5
0
ファイル: ProductController.cs プロジェクト: alisrk/MvcEgitim
        public IActionResult Addproduct()
        {
            List <SelectListItem> brands = new List <SelectListItem>()
            {
                new SelectListItem("reno", "renault"),
                new SelectListItem("merc", "merco")
            };

            productViewModel model = new productViewModel();

            model.brands = brands;

            return(View(model));
        }