public ActionResult ProductEdit(string id) { var product = svc.GetProduct(id); var model = new ProductEditVM() { Product = product }; Regex reg = new Regex(@"^_"); List <BaseFile> proImgs = null; if (!string.IsNullOrEmpty(product.Id) && !reg.IsMatch(product.Id)) { var bfService = new BaseFileService(); proImgs = bfService.GetBaseFiles(product.Id); } ViewBag.ProductImgs = proImgs; return(View(model)); }
public ActionResult UploadImgs(string productId) { OpResult result = null; productId = ReplaceProductId(productId); var files = Request.Files; //var maxFile = 1024 * 1024; var dir = "/Files/" + DateTime.Now.ToString("yyyyMMdd") + "/"; var dirPath = Server.MapPath(dir); if (Directory.Exists(dirPath) == false) { Directory.CreateDirectory(dirPath); } if (files.Count > 0) { var entities = new List <BaseFile>(); var bfService = new BaseFileService(); foreach (var fileKey in files.AllKeys) { var index = fileKey.Split('_')[1].ToInt32(); var file = files[fileKey]; BaseFile entity = null; if (file != null) { // Verify that the user selected a file if (file != null && file.ContentLength > 0) { entity = new BaseFile(); // extract only the fielname entity.OldName = Path.GetFileName(file.FileName); entity.SuffixName = GetSuffix(entity.OldName); entity.NewName = DataHelper.GetSystemID() + "." + entity.SuffixName; entity.Url = dir + entity.NewName; entity.Sorting = index; string filePath = dirPath + entity.NewName; var minFilePath = filePath + "_min" + ".jpg"; var middleFilePath = filePath + "_middle" + ".jpg"; // TODO: need to define destination //var path = Path.Combine(Server.MapPath("~/Files"), fileName); file.SaveAs(filePath); PictureHelper.MakeThumbnail(filePath, minFilePath, 200, 200, "Cut"); PictureHelper.MakeThumbnail(filePath, middleFilePath, 280, 280, "Cut"); } entities.Add(entity); } } var result1 = bfService.SaveBaseFiles(entities, productId, UserCache.CurrentUser.Id); if (result1 != null) { result = OpResult.Success("上传成功", "", result1); } else { result = OpResult.Fail("上传失败"); } } else { result = OpResult.Fail("没有可上传的文件"); } return(Json(result)); }