Example #1
0
        public ActionResult _PartialDeleteFileForm(int fileid)
        {
            File file = db.Files.Where(m => m.fileid == fileid)
                        .Include(m => m.FileExtension).FirstOrDefault();

            return(PartialView(file));
        }
Example #2
0
        public ActionResult ShowFileData(int fileid)
        {
            try
            {
                if (!db.Files.Any(m => m.fileid == fileid))
                {
                    return(RedirectToAction("Partial_Toast", "Toast", NoSuchFile()));
                }

                string fileExt = db.Files.Include(m => m.FileExtension).FirstOrDefault(m => m.fileid == fileid)?.FileExtension?.displayname;

                if (ImageFileExtensions.Any(fileExt.Contains))
                {
                    var file = db.Files.Include(m => m.FileExtension).FirstOrDefault(m => m.fileid == fileid);
                    return(PartialView("_PartialShowFileImage", new FileEditModel(file)));
                }

                if (TextFileExtensions.Any(fileExt.Contains))
                {
                    var file = db.Files.Include(m => m.FileExtension).FirstOrDefault(m => m.fileid == fileid);
                    file.FileContentAsString = file.file_content != null?Encoding.UTF8.GetString(file.file_content) : "";

                    return(PartialView("_PartialShowFileData", new FileEditModel(file)));
                }

                // загрузка данных файла без контента файла
                File fileWithoutData = db.Files.AsEnumerable().Where(m => m.fileid == fileid).Select(m => new File
                {
                    fileid        = m.fileid,
                    FileExtension = m.FileExtension,
                    description   = m.description,
                    displayname   = m.displayname,
                    folderid      = m.folderid
                }).FirstOrDefault();

                string extName      = fileWithoutData.FileExtension?.icon_filename ?? fileWithoutData.FileExtension.displayname + ".svg";
                string relativePath = "/Content/FileIcons/" + extName;
                string fullpath     = HttpContext.Server.MapPath(relativePath);

                if (System.IO.File.Exists(fullpath))
                {
                    fileWithoutData.IconFileName = extName;
                }
                else
                {
                    fileWithoutData.IconFileName = "unknown.svg";
                }

                return(PartialView("_PartialShowFileExtension", new FileEditModel(fileWithoutData)));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Partial_UnknownErrorToast", "Toast"));
            }
        }