public ActionResult SaveFile(DataAccess.Models.File file)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var filetmp = listFiles.Where(p => p.ID == file.FileID).FirstOrDefault();
             if (filetmp != null)
             {
                 listSelectedFiles.Add(new DataAccess.Models.File {
                     Name = filetmp.Name, Type = filetmp.Type, Contents = filetmp.Contents, DocumentTypeID = file.DocumentTypeID, EmployeeID = file.EmployeeID
                 });
             }
             else
             {
                 return(Json(new { warning = "file not found" }));
             }
         }
         else
         {
             return(Json(new { warning = "model is not valid" }));
         }
     }
     catch (Exception e)
     {
         ModelState.AddModelError("", e.Message);
         return(View(file));
     }
     return(PartialView("Partial_Views/_FilesSelected", listSelectedFiles));
 }
        public IActionResult CreateFile([FromForm] InsertFileRequest request)
        {
            if (request.File == null)
            {
                return(BadRequest("Отсутствует файл в запросе"));
            }

            var folder = _folderRepo.FirstOrDefault(f => f.Id == request.FolderId);

            if (folder == null)
            {
                return(BadRequest("Указанная папка не существует"));
            }

            if (_fileRepo.Any(f => f.FileName == request.File.FileName && f.Folder.Id == request.FolderId))
            {
                return(BadRequest("В данной папке уже существует файл с таким именем"));
            }

            var newFile = new File
            {
                FileName = request.File.FileName,
                Folder   = folder,
                FilePath = DiskHelper.SaveToPC(request.File, _folderService.GetFullPath(request.FolderId))
            };

            _fileRepo.Add(newFile);
            _db.SaveChanges();

            return(CreatedAtAction(nameof(GetFile), routeValues: new { fileId = newFile.Id }, newFile.Id));
        }
        public ActionResult SaveFile(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DataAccess.Models.File file = new DataAccess.Models.File();
            var filetmp = listFiles.Where(p => p.ID == id).FirstOrDefault();

            if (filetmp != null)
            {
                file.FileID = filetmp.ID;
                file.Name   = filetmp.Name;
                file.Type   = filetmp.Type;
            }

            ViewBag.DocumentTypeID = new SelectList(db.DocumentTypes, "DocumentTypeID", "Name", file?.DocumentTypeID);
            return(PartialView("Partial_Views/_FilesSaved", file));
        }
        public async Task <ActionResult> SaveFilledFile(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DataAccess.Models.File file = new DataAccess.Models.File();
            var filetmp = await db.FilesTmp.FindAsync(id);

            if (filetmp != null)
            {
                file.FileID = filetmp.ID;
                file.Name   = filetmp.Name;
                file.Type   = filetmp.Type;
            }


            ViewBag.DocumentTypeID = new SelectList(db.DocumentTypes, "DocumentTypeID", "Name", file?.DocumentTypeID);
            return(View(file));
        }
        public async Task <ActionResult> SaveFilledFile(DataAccess.Models.File file)
        {
            FileTmp filetmp = new FileTmp();

            try
            {
                if (ModelState.IsValid)
                {
                    filetmp = await db.FilesTmp.FindAsync(file.FileID);

                    if (filetmp != null)
                    {
                        var newFile = new DataAccess.Models.File {
                            Name = filetmp.Name, Type = filetmp.Type, Contents = filetmp.Contents, DocumentTypeID = file.DocumentTypeID, EmployeeID = file.EmployeeID
                        };
                        db.Files.Add(newFile);
                        listSelectedFiles.Add(newFile);
                        await db.SaveChangesAsync();
                    }
                    else
                    {
                        return(Json(new { warning = "file not found" }));
                    }
                }
                else
                {
                    return(Json(new { warning = "model is not valid" }));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
                return(View(file));
            }
            return(PartialView("_SelectedFiles", listSelectedFiles));
        }