Ejemplo n.º 1
0
        private static List <BookExtendedDomainObject> CreateBookExtended()
        {
            var listExtended = new List <BookExtendedDomainObject>();

            using (ApplicationDbContext dbContext = new ApplicationDbContext())
            {
                var books = dbContext.Books.ToList();

                foreach (var book in books)
                {
                    BookExtendedDomainObject bookExtended = new BookExtendedDomainObject();

                    bookExtended.Passages         = dbContext.Passages.Where(x => x.BookGuid == book.Guid).ToList();
                    bookExtended.BookName         = book.BookName;
                    bookExtended.BookFullName     = book.BookFullName;
                    bookExtended.Guid             = book.Guid;
                    bookExtended.PreviousBookGuid = listExtended.LastOrDefault()?.Guid ?? Guid.Empty;


                    var bookExtendedDomainObject = listExtended.LastOrDefault();
                    if (bookExtendedDomainObject != null)
                    {
                        bookExtendedDomainObject.NextBookGuid = bookExtended.Guid;
                    }


                    bookExtended.BookGlobalNumber = book.BookGlobalNumber;

                    bookExtended.BeforeSave();
                    listExtended.Add(bookExtended);
                }
                dbContext.BooksExtended.AddRange(listExtended);
                dbContext.SaveChanges();
            }
            return(listExtended);
        }
Ejemplo n.º 2
0
        private static List <PassageDomainObject> GetPassages()
        {
            string url  = @"C:\Users\Łukasz\Desktop\Biblia Tysiąclecia - wydanie II poprawione.txt";
            var    text = System.IO.File.ReadAllLines(url);

            var passages = new List <PassageDomainObject>();
            var books    = new List <BookDomainObject>();
            BookDomainObject currentBook = null;
            bool             splitByFour = false;
            int i = 0;

            foreach (var passageString in text)
            {
                //nowa ksiega
                if (string.IsNullOrEmpty(passageString))
                {
                    currentBook = null;
                    splitByFour = false;
                    continue;
                }

                var splitedPassage = passageString.Split();
                var passagesList   = splitedPassage.ToList();
                passagesList.RemoveAll(x => x == "");

                if (currentBook == null)
                {
                    int str;
                    currentBook = new BookDomainObject();
                    books.Add(currentBook);
                    currentBook.Guid             = Guid.NewGuid().GenerateComb();
                    currentBook.BookGlobalNumber = i++;

                    if (passageString.Contains("Pieśń nad Pieśniami"))
                    {
                        splitByFour               = true;
                        currentBook.BookName      = GetBooks().Where(x => x.BookFullName.Contains(splitedPassage[0] + " " + splitedPassage[1])).FirstOrDefault().BookName + " " + splitedPassage[2];
                        currentBook.BookFullName  = splitedPassage[0] + " " + splitedPassage[1] + " " + splitedPassage[2];// + " " + splitedPassage[3];
                        currentBook.SubbookNumber = Int32.Parse(splitedPassage[3]);
                        passagesList.RemoveAt(0);
                    }
                    else if (passageString.Contains("Powtórzonego Prawa"))
                    {
                        splitByFour          = true;
                        currentBook.BookName =
                            GetBooks()
                            .Where(x => x.BookFullName.Contains(splitedPassage[0] + " " + splitedPassage[1]))
                            .FirstOrDefault()
                            .BookName + " " + splitedPassage[2];
                        currentBook.BookFullName  = splitedPassage[0] + " " + splitedPassage[1];// + " " + splitedPassage[2];
                        currentBook.SubbookNumber = Int32.Parse(splitedPassage[2]);
                    }
                    else if (Int32.TryParse(splitedPassage[0], out str))
                    {
                        splitByFour          = true;
                        currentBook.BookName =
                            GetBooks()
                            .Where(x => x.BookFullName.Contains(splitedPassage[0] + " " + splitedPassage[1]))
                            .FirstOrDefault()
                            .BookName + " " + splitedPassage[2];
                        currentBook.BookFullName  = splitedPassage[0] + " " + splitedPassage[1];// + " " + splitedPassage[2];
                        currentBook.SubbookNumber = Int32.Parse(splitedPassage[2]);
                    }
                    else
                    {
                        splitByFour          = false;
                        currentBook.BookName =
                            GetBooks().Where(x => x.BookFullName.Contains(splitedPassage[0])).FirstOrDefault().BookName + " " + splitedPassage[1];
                        currentBook.BookFullName  = splitedPassage[0];
                        currentBook.SubbookNumber = Int32.Parse(splitedPassage[1]);
                    }
                }


                passagesList.RemoveAt(0);
                passagesList.RemoveAt(0);

                if (splitByFour)
                {
                    passagesList.RemoveAt(0);
                }


                var passage = new PassageDomainObject();
                passage.PassageNumber = Int32.Parse(passagesList[0]);

                passagesList.RemoveAt(0);

                passage.PassageText = string.Join(" ", passagesList);

                passage.BookGuid = currentBook.Guid;
                passage.Book     = currentBook.BookName;
                passages.Add(passage);
            }

            passages.ForEach(x => x.Guid = Guid.Empty.GenerateComb());

            var bookExtended = new BookExtendedDomainObject();

            bookExtended.Passages = passages;

            using (ApplicationDbContext dbContext = new ApplicationDbContext())
            {
                dbContext.Books.AddRange(books);
                dbContext.Passages.AddRange(passages);
                dbContext.SaveChanges();
            }

            return(passages);
        }