コード例 #1
0
        public IActionResult AddProduct()
        {
            var model = new UIProductSupCategory();
            var c     = new SubCategoryRepository().GetAll("Id", "Name");

            if (c.Count > 0)
            {
                foreach (var item in c)
                {
                    model.Subcategores.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem(item.Name, item.Id.ToString()));
                }
            }

            return(View(model));
        }
コード例 #2
0
        public IActionResult UpdateProduct(int id)
        {
            var pr    = repository.GetByColumName("Id", id);
            var model = new UIProductSupCategory(); model.Product = pr.FirstOrDefault();
            var c     = new SubCategoryRepository().GetAll("Id", "Name");

            if (c.Count > 0)
            {
                foreach (var item in c)
                {
                    model.Subcategores.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem(item.Name, item.Id.ToString()));
                }
            }

            return(View(model));
        }
コード例 #3
0
        public IActionResult AddProduct(UIProductSupCategory model)
        {
            string filename = null;

            if (model.Img != null)
            {
                filename = Guid.NewGuid().ToString() + "_"
                           + model.Img.FileName.Split("\\").LastOrDefault();
                string fn = Path.Combine(Environment.WebRootPath, "userimg", filename);
                using (FileStream fs = new FileStream(fn, FileMode.Create))

                {
                    model.Img.CopyTo(fs);
                }
            }
            repository.Insert(model.Product);
            return(RedirectToAction("AllProduct"));
        }