public async Task <IActionResult> NewCategory() { FileCategories category = new FileCategories { CategoryLabel = Request.Form["categoryLabel"] }; await _context.FileCategories.AddAsync(category); try { await _context.SaveChangesAsync(); if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", category.CategoryLabel))) { Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", category.CategoryLabel)); } } catch (Exception) { return(View("../Shared/Error")); } return(RedirectToAction("Index")); }
public MaxFileSizeAttribute(FileCategories FileCategory) { _fileCategory = FileCategory; if (FileCategory == FileCategories.Image) { this.MaxFileSize = AcceptedImages.MaximumAcceptedSize; } else if (FileCategory == FileCategories.Text) { this.MaxFileSize = AcceptedDocuments.MaximumAcceptedSize; } }
private static bool IsCategory(IFileSystemInfo fsInfo, FileCategories category) { FileAttributes?attrs = category.GetFileAttrs(); if (attrs is not null) { return(fsInfo.Attributes.HasFlag((FileAttributes)attrs)); } string fileExt = AppExtension.GetExtentionCoreFromPath(fsInfo.Name).ToLowerInvariant(); return(category.GetFileExtPattern().Contains(fileExt)); }
public async Task <IActionResult> CategoryUpdate(int?ImgId, int?CatId) { if (!HttpContext.Session.Keys.Contains <string>("Authenticated")) { return(View("Unauthorized")); } if (ImgId == null || CatId == null) { return(NotFound()); } var img = await _context.Images.FirstAsync <Images>(i => i.ImageId == ImgId); if (img == null) { return(NotFound()); } FileCategories newCategory = await _context.FileCategories.FirstAsync <FileCategories>(i => i.CategoryId == CatId); FileCategories oldCategory = await _context.FileCategories.FirstAsync <FileCategories>(i => i.CategoryId == img.CategoryId); img.CategoryId = (int)CatId; _context.Images.Update(img); try { using (var oldStream = new FileStream(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", oldCategory.CategoryLabel, img.ImgFileName), FileMode.OpenOrCreate)) { using (var newStream = new FileStream(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", newCategory.CategoryLabel, img.ImgFileName), FileMode.OpenOrCreate)) { await oldStream.CopyToAsync(newStream); } } System.IO.File.Delete(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", oldCategory.CategoryLabel, img.ImgFileName))); await _context.SaveChangesAsync(); } catch (Exception) { return(View("../Shared/Error", img)); } return(RedirectToAction("Index")); }
public IActionResult Upload(List <IFormFile> formFiles) { if (!HttpContext.Session.Keys.Contains <string>("Authenticated")) { return(View("Unauthorized")); } foreach (var file in Request.Form.Files) { var path = ""; int index = file.FileName.IndexOf('.') + 1; string fileType = file.FileName.Substring(index).ToLower(); int categoryId = Int32.Parse(Request.Form["categoryId"]); FileCategories category = _context.FileCategories.First <FileCategories>(c => c.CategoryId == categoryId); path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", category.CategoryLabel, file.FileName); try { Images img = new Images(); img.ImgFileName = file.FileName; img.UploadedDate = DateTime.Now; img.IsPublished = 0; img.CategoryId = categoryId; using (var stream = new FileStream(path, FileMode.Create)) { file.CopyTo(stream); } _context.Images.Add(img); } catch (IOException) { return(View("../Shared/Error")); } _context.SaveChanges(); } return(RedirectToAction("Index")); }
/* * [HttpGet] * public async Task<IActionResult> LoadAllFiles() * { * if (!HttpContext.Session.Keys.Contains<string>("Authenticated")) * { * return View("Unauthorized"); * } * * AllFilesViewModel model = new AllFilesViewModel * { * Images = await _context.Images.ToListAsync<Images>(), * Files = await _context.Files.ToListAsync<Files>(), * Categories = await _context.FileCategories.ToListAsync<FileCategories>(), * FileFolders = await _context.Folders.ToListAsync<Folders>() * }; * * model.Categories = model.Categories.OrderBy<FileCategories, int>(i => i.CategoryId); * model.Images = model.Images.OrderByDescending<Images, DateTime>(t => t.UploadedDate); * model.Files = model.Files.OrderByDescending<Files, DateTime>(t => t.UploadedDate); * * return View("AllFiles", model); * } */ public async Task <IActionResult> Delete(int?Id) { if (!HttpContext.Session.Keys.Contains <string>("Authenticated")) { return(View("Unauthorized")); } if (Id == null) { return(NotFound()); } var img = await _context.FindAsync <Images>(Id); if (img == null) { return(NotFound()); } FileCategories category = await _context.FileCategories.FirstAsync(c => c.CategoryId == img.CategoryId); var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", category.CategoryLabel, img.ImgFileName); var fileInfo = new FileInfo(path); try { _context.Images.Remove(img); if (fileInfo.Exists) { fileInfo.Delete(); } await _context.SaveChangesAsync(); } catch (Exception) { return(View("../Shared/Error")); } return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteCategory(int?Id) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images"); List <Images> imgList = await _context.Images.Where <Images>(i => i.CategoryId == Id).ToListAsync <Images>(); FileCategories oldCategory = await _context.FileCategories.FirstAsync <FileCategories>(c => c.CategoryId == Id); if (imgList.Count() > 0) { try { foreach (Images img in imgList) { string oldPath = Path.Combine(path, oldCategory.CategoryLabel, img.ImgFileName); var file = new FileInfo(oldPath); file.MoveTo(Path.Combine(path, "No Category", img.ImgFileName)); img.CategoryId = 0; } Directory.Delete(Path.Combine(path, oldCategory.CategoryLabel)); _context.FileCategories.Remove(oldCategory); await _context.SaveChangesAsync(); } catch (Exception) { return(View("../Shared/Error")); } } else { _context.FileCategories.Remove(oldCategory); Directory.Delete(Path.Combine(path, oldCategory.CategoryLabel)); await _context.SaveChangesAsync(); } List <FileCategories> categoryList = await _context.FileCategories.ToListAsync <FileCategories>(); return(RedirectToAction("Index", categoryList)); }
public async Task <IActionResult> EditCategory() { string newLabel = Request.Form["newLabel"]; int categoryId = Int32.Parse(Request.Form["categoryId"]); FileCategories category = await _context.FileCategories.FirstAsync <FileCategories>(i => i.CategoryId == categoryId); string oldPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", category.CategoryLabel); string newPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Images", newLabel); try { Directory.Move(oldPath, newPath); category.CategoryLabel = newLabel; _context.FileCategories.Update(category); await _context.SaveChangesAsync(); } catch (Exception) { return(View("../Shared/Error")); } return(RedirectToAction("Index")); }
/// <summary> /// FileExtPattern属性の取得 /// </summary> public static string[] GetFileExtPattern(this FileCategories value) => value.GetAttribute <FileCategories, FileExtPatternAttribute>()?.FileExtPattern ?? Array.Empty <string>();
/// <summary> /// FileAttrs属性の取得 /// </summary> public static FileAttributes?GetFileAttrs(this FileCategories value) => value.GetAttribute <FileCategories, FileAttrsAttribute>()?.FileAttr;
private SelectList FileList(FileCategories category, int? selectedId) { return new SelectList(Repository.ListFiles.Where(f => f.Category == category.ToString()).OrderBy(f => f.FileName), "Id", "FileName", selectedId ?? default(int)); }
public void SetDataSet(float[][][] paDataSet) { DataSet = paDataSet; MetaData.OutputSize = paDataSet.Length; MetaData.SetClassLabels(FileCategories.Select(fc => fc.CategoryName).ToArray()); }