示例#1
0
        public static async Task AddBookAsync(SeniorLibraryContext context)
        {
            System.Diagnostics.Debug.WriteLine("Adding Books");
            string currentDir = Directory.GetCurrentDirectory();
            string bookRoot   = currentDir + @"/book";
            string addedRoot  = bookRoot + @"/Added";

            string[] entries = Directory.GetFiles(bookRoot);
            Console.WriteLine(currentDir);
            foreach (string filePath in entries)
            {
                string fileName = Path.GetFileName(filePath);
                //Prepare tools needed for filereading
                //Console.WriteLine(Path.GetFileName(filePath));
                byte[]       fileContent  = null;
                FileStream   fs           = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                BinaryReader binaryReader = new System.IO.BinaryReader(fs);
                long         byteLength   = new FileInfo(filePath).Length;
                fileContent = binaryReader.ReadBytes((Int32)byteLength);
                fs.Close();
                fs.Dispose();
                binaryReader.Close();
                //Create a book object
                var book = new Book();
                book.Name      = fileName;
                book.DataFiles = fileContent;
                book.CreatedOn = DateTime.Now;
                //Insert to database
                File.Move(filePath, addedRoot + @"/" + fileName);
                await context.Book.AddAsync(book);

                await context.SaveChangesAsync();

                System.Diagnostics.Debug.WriteLine("Successfully Added" + fileName + "!! to the database");
            }
            System.Diagnostics.Debug.WriteLine("DONE !!!!!!!!!!!!!!");
        }
示例#2
0
 public DownloadModel(UserManager <ApplicationUser> userManager
                      , SeniorLibrary.Data.SeniorLibraryContext context)
 {
     _context     = context;
     _userManager = userManager;
 }
示例#3
0
 public IndexModel(SeniorLibrary.Data.SeniorLibraryContext context)
 {
     _context = context;
 }
示例#4
0
 public EditModel(SeniorLibrary.Data.SeniorLibraryContext context)
 {
     _context = context;
 }
示例#5
0
 public DetailsModel(SeniorLibrary.Data.SeniorLibraryContext context)
 {
     _context = context;
 }
示例#6
0
 public DeleteModel(SeniorLibrary.Data.SeniorLibraryContext context)
 {
     _context = context;
 }