public ActionResult Edit() { Podreczniki dataBase = repository.Podrecznikis.FirstOrDefault(); if (dataBase == null) { dataBase = new Podreczniki { Tresc = "Wpisz tutaj treść." }; repository.SavePodreczniki(dataBase); } ViewBag.fileList = Directory .EnumerateFiles(fileDirectory, "*", SearchOption.AllDirectories) .Select(Path.GetFileName); ViewBag.fileDirectory = fileDirectory; return(View(dataBase)); }
public ActionResult DeleteFile(string file) { ViewBag.fileList = Directory .EnumerateFiles(fileDirectory, "*", SearchOption.AllDirectories) .Select(Path.GetFileName); ViewBag.fileDirectory = fileDirectory; var fileName = ""; fileName = file; var fullPath = Path.Combine(fileDirectory, file); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); ViewBag.deleteSuccess = "true"; } Podreczniki dataBase = repository.Podrecznikis.FirstOrDefault(); return(View("Edit", dataBase)); }
public async Task <IActionResult> Edit(Podreczniki modelReturned, List <IFormFile> files) { Podreczniki dataBase = repository.Podrecznikis.FirstOrDefault(); dataBase.Tresc = HtmlUtility.RemoveInvalidHtmlTags(modelReturned.Tresc); repository.SavePodreczniki(dataBase); if (files != null) { long size = files.Sum(f => f.Length); var filePath = ""; foreach (var formFile in files) { filePath = Path.Combine(fileDirectory, formFile.FileName); if (formFile.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { await formFile.CopyToAsync(stream); } } } } return(RedirectToAction(nameof(Index))); }