private void AddFolder(Category model, string[] CategoryFolder)
 {
     if (CategoryFolder != null)
     {
         foreach (var folder in CategoryFolder)
         {
             model.CategoryFolder.Add(new CategoryFolder {
                 FolderId = Convert.ToInt32(folder)
             });
             _context.SaveChanges();
         }
     }
 }
 private void AddFolder(Document model, string[] DocumentFolder)
 {
     if (DocumentFolder != null)
     {
         foreach (var folder in DocumentFolder)
         {
             model.DocumentFolder.Add(new DocumentFolder {
                 FolderId = Convert.ToInt32(folder)
             });
             _context.SaveChanges();
         }
     }
 }
        private void AddFiles(Folder model, List <IFormFile> Files)
        {
            if (Files != null && Files.Count > 0)
            {
                var newPath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\uploaded_files");
                if (!Directory.Exists(newPath))
                {
                    Directory.CreateDirectory(newPath);
                }
                foreach (IFormFile item in Files)
                {
                    if (item.Length > 0)
                    {
                        string fileName = ContentDispositionHeaderValue.Parse(item.ContentDisposition).FileName.Trim('"');
                        // If file with same name exists delete it
                        string fullPath = Path.Combine(newPath, fileName);
                        if (System.IO.File.Exists(fullPath))
                        {
                            System.IO.File.Delete(fullPath);
                        }

                        using (var stream = new FileStream(fullPath, FileMode.Create))
                        {
                            item.CopyTo(stream);
                        }
                        var document = new Document {
                            FilePath = item.FileName
                        };
                        _context.Add(document);
                        _context.SaveChanges();
                        model.DocumentFolder.Add(new DocumentFolder {
                            DocumentId = document.DocumentId
                        });
                    }
                }
            }
        }