Ejemplo n.º 1
0
        public void Add(Book pEbook, string pAuthor, string pReview, string pEbookSource, string pOldEbookFile)
        {
            string strBookName = "";

            strBookName = NameCreater.CreateName(pEbook.bok_Title);
            string shortDirectory = NameCreater.CreateLocation(ConvertData.ToList(pAuthor)[0], strBookName);
            string newDirectory   = LycuteApplication.GetLocationString() + "\\" + shortDirectory;

            //check new directory is availble
            Directory.CreateDirectory(newDirectory);

            //Copy image
            string strFileType = "";
            string strImageURL = "";

            if (pEbook.bok_ImageURl != "" && pEbook.bok_ImageURl != null)
            {
                string[] arrayImageSourceURL = pEbook.bok_ImageURl.Split(new string[] { "///" }, StringSplitOptions.None);
                string   pImageSourceURL     = arrayImageSourceURL[arrayImageSourceURL.Count() - 1].Replace("/", "\\");

                strFileType = NameCreater.GetFileType(pImageSourceURL);
                strImageURL = NameCreater.FileLocation(newDirectory, "cover." + strFileType);
                //copy image
                if (pImageSourceURL != strImageURL)
                {
                    copy.Copy(pImageSourceURL, strImageURL, "file");
                }
            }
            //copy file
            copy.Copy(pEbookSource, NameCreater.FileLocation(newDirectory, pEbook.bok_Title + "." + NameCreater.GetFileType(pOldEbookFile)), "file");
            //edit review
            EditReview(newDirectory + "\\review.xml", pReview);
            //Save data
            using (LibraryEntities mainDB = new LibraryEntities())
            {
                Book b = new Book();
                b.bok_Edition = pEbook.bok_Edition;
                if (strFileType != "")
                {
                    b.bok_ImageURl = "cover." + strFileType;
                }
                b.bok_ISBN     = pEbook.bok_ISBN;
                b.bok_ID       = System.Guid.NewGuid().ToString();
                b.bok_Modified = pEbook.bok_Modified;
                b.bok_Rank     = pEbook.bok_Rank;
                b.bok_Title    = pEbook.bok_Title;
                b.bok_Volume   = pEbook.bok_Volume;
                b.bok_Year     = pEbook.bok_Year;
                b.bok_Location = pEbook.bok_Title + "." + NameCreater.GetFileType(pOldEbookFile);
                b.lng_ID       = "0";
                b.bok_Review   = "review.xml";

                Publisher pbl = publisherLib.AddPublisher(pEbook.Publisher, b.Publisher);
                b.pbl_ID = pbl.pbl_ID;


                List <string> auNames = authorLib.AddAuthor(pEbook.Authors, null, "");

                foreach (string name in auNames)
                {
                    var aut = (from author in mainDB.Authors
                               where author.ath_Name == name
                               select author).First();
                    aut.Books.Add(b);
                    //mainDB.AddToAuthors(au);
                }

                mainDB.AddToBooks(b);
                mainDB.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        /*Edit ebook*/
        public void Edit(Book pEbook, string pAuthor, string pOldDirectory, string pReview, string pOldEbookFile)
        {
            string strBookName = "";

            //error to create folder with voulume
            //if(pEbook.bok_Volume==1){
            strBookName = NameCreater.CreateName(pEbook.bok_Title);
            //}
            //else
            //{
            //    strBookName = NameCreater.CreateName(pEbook.bok_Title,pEbook.bok_Volume.ToString());
            //}
            string shortDirectory = NameCreater.CreateLocation(ConvertData.ToList(pAuthor)[0], strBookName);
            string newDirectory   = LycuteApplication.GetLocationString() + "\\" + shortDirectory;

            //check new directory is availble
            if (pOldDirectory != newDirectory)
            {
                //if (!copy.DirectoryIsExist(newDirectory))
                //{
                Directory.CreateDirectory(newDirectory);
                copy.Copy(pOldDirectory, newDirectory, pOldEbookFile, pEbook.bok_Title);
                copy.Delete(pOldDirectory, "folder");
                //}
            }
            //Copy image
            string strFileType = "";
            string strImageURL = "";

            if (pEbook.bok_ImageURl != "" && pEbook.bok_ImageURl != null)
            {
                string[] arrayImageSourceURL = pEbook.bok_ImageURl.Split(new string[] { "///" }, StringSplitOptions.None);
                string   pImageSourceURL     = arrayImageSourceURL[arrayImageSourceURL.Count() - 1].Replace("/", "\\");

                strFileType = NameCreater.GetFileType(pImageSourceURL);
                strImageURL = NameCreater.FileLocation(newDirectory, "cover." + strFileType);
                //copy image
                if (pImageSourceURL != strImageURL)
                {
                    copy.Copy(pImageSourceURL, strImageURL, "file");
                }
            }
            //Edit book
            LibraryEntities mainDB = new LibraryEntities();
            var             ebooks = (from ebook in mainDB.Books
                                      where ebook.bok_ID == pEbook.bok_ID
                                      select ebook).First();

            ebooks.bok_Edition  = pEbook.bok_Edition;
            ebooks.bok_ISBN     = pEbook.bok_ISBN;
            ebooks.bok_Modified = pEbook.bok_Modified;
            ebooks.bok_Rank     = pEbook.bok_Rank;
            ebooks.bok_Title    = pEbook.bok_Title;
            ebooks.bok_Volume   = pEbook.bok_Volume;
            ebooks.bok_Year     = pEbook.bok_Year;
            ebooks.bok_Location = pEbook.bok_Title + "." + NameCreater.GetFileType(pOldEbookFile);
            //add publisher if it is not exist and add publisher to EBook
            Publisher pbl = publisherLib.AddPublisher(pEbook.Publisher, ebooks.Publisher);

            if (pbl != null)
            {
                ebooks.pbl_ID = pbl.pbl_ID;
            }
            //add author
            List <string> auNames = authorLib.AddAuthor(pEbook.Authors, ebooks.Authors, ebooks.bok_ID);

            foreach (string name in auNames)
            {
                var aut = (from author in mainDB.Authors
                           where author.ath_Name == name
                           select author).First();
                aut.Books.Add(ebooks);
                //mainDB.AddToAuthors(au);
            }
            //save to database
            mainDB.SaveChanges();
            //edit review
            EditReview(newDirectory + "\\review.xml", pReview);
        }