Esempio n. 1
0
        public ActionResult AddWork(string Title, string Description, int WorkCategory)
        {
            if (CurrentUser.Role > Role.Business)
            {
                Product product = new Product();
                product.Belong = ProductBelong.作品;
                product.Description = Description;
                product.Time = DateTime.Now;
                product.ProductCategoryID = WorkCategory;

                product.Title = Title;
                product.UserID = CurrentUser.ID;
                db.Products.Add(product);
                db.SaveChanges();
                string root = "~/ProductFile/AdminFiles/" + product.ID + "/";
                var phicyPath = HostingEnvironment.MapPath(root);
                Directory.CreateDirectory(phicyPath);
                return Redirect("/Admin/ProductManager");
            }
            else
            {
                ProductUserInfo info = new ProductUserInfo();
                info.Title = Title;
                info.Description = Description;
                info.Belong = ProductBelong.作品;
                info.Time = DateTime.Now;
                info.AuthorID = CurrentUser.ID;
                info.ProductCategoryID = WorkCategory;
                info.Status = ProductUserInfoStatusEnum.未提交;
                db.ProductUserInfos.Add(info);
                db.SaveChanges();
                string root = "~/ProductFile/UserFiles/" + info.ID + "/";
                var phicyPath = HostingEnvironment.MapPath(root);
                Directory.CreateDirectory(phicyPath);
                return Redirect("/Admin/UserProductManager");
            }
        }
Esempio n. 2
0
 public ActionResult Show(int id)
 {
     Product product = new Product();
     product = db.Products.Find(id);
     vProduct pro = new vProduct(product);
     if (pro.ProductVideo == null)
     {
         ViewBag.ProductVideo = 0;
     }
     else
     {
         ViewBag.ProductVideo = 1;
     }
     ViewBag.Product = pro;
     return View();
 }
Esempio n. 3
0
        public ActionResult UserProductPass(int id)
        {
            ProductUserInfo info = new ProductUserInfo();
            info = db.ProductUserInfos.Find(id);
            info.Status = ProductUserInfoStatusEnum.审核通过;
            db.SaveChanges();

            if (info.ProductID != null)
            {
                Product product = new Product();
                product = db.Products.Find(info.ProductID);

                product.Title = info.Title;
                product.Description = info.Description;

                List<ProductFile> _files = new List<ProductFile>();
                _files = db.ProductFiles.Where(pf => pf.ProductID == product.ID).ToList();
                foreach (var item in _files)
                {
                    item.IsUse = false;
                }

                List<ProductFile> files = new List<ProductFile>();
                files = db.ProductFiles.Where(pf => pf.PUId == id).ToList();
                foreach (var item in files)
                {
                    item.ProductID = product.ID;
                    item.IsUse = true;
                }
                db.SaveChanges();
            }
            else
            {
                Product product = new Product();
                product.Title = info.Title;
                product.Description = info.Description;
                product.Price = info.Price.ToString();
                product.ProductCategoryID = info.ProductCategoryID;
                product.Time = DateTime.Now;
                product.UserID = CurrentUser.ID;
                product.Belong = info.Belong;
                db.Products.Add(product);
                db.SaveChanges();

                List<ProductFile> files = new List<ProductFile>();
                files = db.ProductFiles.Where(pf => pf.PUId == info.ID).ToList();
                foreach (var item in files)
                {
                    item.ProductID = product.ID;
                    item.IsUse = true;
                }
                info.ProductID = product.ID;
                db.SaveChanges();

                string root = "~/ProductFile/AdminFiles/" + product.ID + "/";
                var phicyPath = HostingEnvironment.MapPath(root);
                Directory.CreateDirectory(phicyPath);

            }

            return Redirect("/Admin/UserProductInfo");
        }
Esempio n. 4
0
 public ActionResult ProductEdit(Product model)
 {
     Product product = db.Products.Find(model.ID);
     product.Title = model.Title;
     product.Description = model.Description;
     product.Price = model.Price;
     //product.ProductCategory = model.ProductCategory;
     db.SaveChanges();
     return Redirect("/Admin/ProductShow/" + model.ID);
 }
Esempio n. 5
0
        public ActionResult ProductDelete(int id)
        {
            if (CurrentUser.Role == Role.Admin)
            {
                List<ProductFile> files = new List<ProductFile>();
                files = db.ProductFiles.Where(pf => pf.ProductID == id && pf.PUId == null).ToList();
                Product product = new Product();
                product = db.Products.Find(id);
                foreach (var item in files)
                {
                    db.ProductFiles.Remove(item);
                }
                db.SaveChanges();
                db.Products.Remove(product);
                db.SaveChanges();
                string root = "~/ProductFile/AdminFiles/" + product.ID + "/";
                var phicyPath = HostingEnvironment.MapPath(root);
                DirectoryInfo di = new DirectoryInfo(phicyPath);

                di.Delete(true);
            }
            else
            {
                List<ProductFile> files = new List<ProductFile>();
                files = db.ProductFiles.Where(pf => pf.PUId == id).ToList();
                ProductUserInfo product = new ProductUserInfo();
                product = db.ProductUserInfos.Find(id);
                foreach (var item in files)
                {
                    db.ProductFiles.Remove(item);
                }
                db.ProductUserInfos.Remove(product);
                db.SaveChanges();
                string root = "~/ProductFile/UserFiles/" + product.ID + "/";
                var phicyPath = HostingEnvironment.MapPath(root);

                DirectoryInfo di = new DirectoryInfo(phicyPath);
                di.Delete(true);
            }
            return Content("ok");
        }
Esempio n. 6
0
        public ActionResult AddProduct(Product model)
        {
            model.UserID = CurrentUser.ID;
            model.Time = DateTime.Now;
            db.Products.Add(model);
            db.SaveChanges();

            string root = "~/ProductFile/" + model.Title + "/";
            var phicyPath = HostingEnvironment.MapPath(root);
            Directory.CreateDirectory(phicyPath);

            return Redirect("/Admin/ProductManager");
        }
Esempio n. 7
0
        public ActionResult ProductDelete(int id)
        {
            List<ProductFile> files = new List<ProductFile>();
            files = db.ProductFiles.Where(pf => pf.ProductID == id).ToList();
            Product product = new Product();
            product = db.Products.Find(id);
            foreach (var item in files)
            {
                db.ProductFiles.Remove(item);
            }
            db.Products.Remove(product);
            db.SaveChanges();
            string root = "~/ProductFile/" + product.Title + "/";
            var phicyPath = HostingEnvironment.MapPath(root);

            DirectoryInfo di = new DirectoryInfo(phicyPath);
            di.Delete(true);

            return Content("ok");
        }