public ActionResult ShowProductUserRecord(int id) { var record = new ProductUserInfo(); record = db.ProductUserInfos.Find(id); User user = db.Users.Find(CurrentUser.ID); ViewBag.User = user; return View(new vUserProductInfo(record)); }
/// <summary> /// 上传视频 /// </summary> /// <param name="ProductID"></param> /// <returns></returns> public ActionResult VideoUpload(int ProductID, int? InfoID) { HttpPostedFileBase file = Request.Files[0]; if (file != null) { if (InfoID == null) { ProductUserInfo info = new ProductUserInfo(); info.Time = DateTime.Now; info.ProductID = ProductID; info.Status = ProductUserInfoStatusEnum.审核中; info.AuthorID = CurrentUser.ID; db.ProductUserInfos.Add(info); db.SaveChanges(); InfoID = info.ID; } string random = Helpers.DateHelper.GetTimeStamp(); Product product = db.Products.Find(ProductID); ProductFile productFile = new ProductFile(); productFile.ProductID = ProductID; productFile.FileTypeAsInt = 1; string root = "~/ProductFile/" + product.ID + "/"; var phicyPath = HostingEnvironment.MapPath(root); file.SaveAs(phicyPath + random + file.FileName); var exten = Path.GetExtension(file.FileName); if (!exten.Equals(".flv")) { var video = new VideoFile(phicyPath + random + file.FileName); video.Convert(".flv", Quality.Medium).MoveTo(phicyPath + random + ".flv"); productFile.Path = "/ProductFile/" + product.ID + "/" + random + ".flv"; if (System.IO.File.Exists(phicyPath + random + file.FileName)) { //如果存在则删除 System.IO.File.Delete(phicyPath + random + file.FileName); } } else { productFile.Path = "/ProductFile/" + product.ID + "/" + random + file.FileName; } productFile.PUId = InfoID; db.ProductFiles.Add(productFile); db.SaveChanges(); return Json(new { filePath = productFile.Path, PUId = InfoID }); } else { return Json(new { filePath = "" }); } }
public ActionResult EditProductInfo(string Description, string Title, int ProductID, int? InfoID) { if (InfoID == null) { ProductUserInfo info = new ProductUserInfo(); info.Description = Description; info.Title = Title; info.ProductID = ProductID; info.Time = DateTime.Now; info.AuthorID = CurrentUser.ID; db.ProductUserInfos.Add(info); db.SaveChanges(); } else { ProductUserInfo info = new ProductUserInfo(); info = db.ProductUserInfos.Find(InfoID); info.Description = Description; info.Title = Title; info.ProductID = ProductID; db.SaveChanges(); } return Redirect("/User/ProductShow/"+ ProductID); }
/// <summary> /// 上传图片 /// </summary> /// <param name="ProductID"></param> /// <returns></returns> public ActionResult ImageUpload(int ProductID, int? InfoID) { HttpPostedFileBase file = Request.Files[0]; if (file != null) { if (InfoID == null) { ProductUserInfo info = new ProductUserInfo(); info.Time = DateTime.Now; info.ProductID = ProductID; info.Status = ProductUserInfoStatusEnum.审核中; info.AuthorID = CurrentUser.ID; db.ProductUserInfos.Add(info); db.SaveChanges(); InfoID = info.ID; } string random = Helpers.DateHelper.GetTimeStamp(); Product product = db.Products.Find(ProductID); ProductFile productFile = new ProductFile(); productFile.ProductID = ProductID; productFile.FileTypeAsInt = 0; productFile.Source = SourceEnum.管理员; productFile.IsUse = false; string root = "~/ProductFile/" + product.ID + "/"; var phicyPath = HostingEnvironment.MapPath(root); file.SaveAs(phicyPath + random + file.FileName); productFile.Path = "/ProductFile/" + product.ID + "/" + random + file.FileName; productFile.PUId = InfoID; db.ProductFiles.Add(productFile); db.SaveChanges(); return Json(new { filePath = productFile.Path, PUId = InfoID }); } else { return Json(new { filePath = "" }); } }
public ActionResult UserSubmitProduct(int id) { ProductUserInfo info = new ProductUserInfo(); info = db.ProductUserInfos.Find(id); info.Status = ProductUserInfoStatusEnum.审核中; db.SaveChanges(); return Redirect("/Admin/UserProductManager/"); }
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"); } }
public ActionResult UserProductNotPass(int id) { ProductUserInfo info = new ProductUserInfo(); info = db.ProductUserInfos.Find(id); info.Status = ProductUserInfoStatusEnum.审核不通过; db.SaveChanges(); return Redirect("/Admin/UserProductInfo"); }
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"); }
public ActionResult UserProductEdit(int ID, string Description, string Title, double Price, int TwoProductCategory) { ProductUserInfo info = new ProductUserInfo(); info = db.ProductUserInfos.Find(ID); info.Description = Description; info.Title = Title; info.Price = (decimal)Price; info.ProductCategoryID = TwoProductCategory; db.SaveChanges(); return Redirect("/Admin/UseProductShow/" + ID); }
public ActionResult UserProductEdit(int id) { ProductUserInfo info = new ProductUserInfo(); info = db.ProductUserInfos.Find(id); List<ProductCategory> categories = new List<ProductCategory>(); categories = db.ProductCategories.Where(pc => (pc.FatherID == null || pc.FatherID == 0)).ToList(); ViewBag.OneProductCategories = categories; return View(new vUserProductInfo(info)); }
public ActionResult UseProductShowDelete(int id) { List<ProductFile> files = new List<ProductFile>(); List<ProductFile> _files = new List<ProductFile>(); files = db.ProductFiles.Where(pf => pf.PUId == id && pf.IsUse == false).ToList(); _files = db.ProductFiles.Where(pf => pf.PUId == id && pf.IsUse == true).ToList(); ProductUserInfo info = new ProductUserInfo(); info = db.ProductUserInfos.Find(id); foreach (var item in _files) { item.PUId = null; } foreach (var item in files) { db.ProductFiles.Remove(item); } db.ProductUserInfos.Remove(info); db.SaveChanges(); foreach (var item in files) { var phicyPath = HostingEnvironment.MapPath(item.Path); if (System.IO.File.Exists(phicyPath)) { System.IO.File.Delete(phicyPath); } } return Content("ok"); }
public ActionResult UseProductShow(int id) { ProductUserInfo info = new ProductUserInfo(); info = db.ProductUserInfos.Find(id); return View(new vUserProductInfo(info)); }
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"); }