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 DeleteUpload(UploadedFile vm) { var upload = Repository.GetUploadedFile(vm.Id); Repository.Delete(upload); Repository.Save(); return RedirectToAction("uploadcategory", new { id = upload.Category }); }
partial void DeleteUploadedFile(UploadedFile instance);
partial void UpdateUploadedFile(UploadedFile instance);
partial void InsertUploadedFile(UploadedFile instance);
public void Delete(UploadedFile file) { _db.UploadedFiles.DeleteOnSubmit(file); }
public void Add(UploadedFile file) { _db.UploadedFiles.InsertOnSubmit(file); }