public ActionResult ReplaceUpload(FileUpload vm) { var upload = Repository.GetUploadedFile(vm.ReplaceId); if (upload == null) return HttpNotFound(); var file = Request.Files[0]; if (file.ContentLength == 0) ModelState.AddModelError("", Phrases.ValidationEmptyOrNoFile); if (file.ContentLength > 10485760) ModelState.AddModelError("", Phrases.ValidationFileTooLarge); if (!ModelState.IsValid) { return View(vm); } var fileData = new byte[file.ContentLength]; file.InputStream.Read(fileData, 0, fileData.Length); upload.FileName = file.FileName.Sanitise(); upload.ContentType = file.ContentType; upload.ContentLength = file.ContentLength; upload.Data = fileData; Repository.Save(); return RedirectToAction("uploadcategory", new { id = vm.FileCategory }); }
public ActionResult CreateUpload(FileUpload vm) { var file = Request.Files[0]; if (file.ContentLength == 0) ModelState.AddModelError("", Phrases.ValidationEmptyOrNoFile); if (file.ContentLength > 10485760) ModelState.AddModelError("", Phrases.ValidationFileTooLarge); if (Repository.GetUploadedFile(vm.FileCategory, file.FileName.Sanitise()) != null) ModelState.AddModelError("", Phrases.ValidationFileExists); if (!ModelState.IsValid) { return View(vm); } var fileData = new byte[file.ContentLength]; file.InputStream.Read(fileData, 0, fileData.Length); var upload = new UploadedFile { FileName = file.FileName.Sanitise(), ContentType = file.ContentType, ContentLength = file.ContentLength, Category = vm.FileCategory, Data = fileData }; Repository.Add(upload); Repository.Save(); return RedirectToAction("uploadcategory", new { id = vm.FileCategory }); }
public ActionResult ReplaceUpload(int id) { var upload = Repository.GetUploadedFile(id); if (upload == null) return HttpNotFound(); var vm = new FileUpload { FileCategory = upload.Category, ReplaceId = id }; return View(vm); }
public ActionResult CreateUpload(string id) { var vm = new FileUpload { FileCategory = id ?? string.Empty }; return View(vm); }