コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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)));
        }