Beispiel #1
0
        public static List<Book> GetAllBooksByAuthor(Author author)
        {
            List<Book> result = new List<Book>();

            using (var context = new BookDBDataContext())
            {
                result = (from book in context.Books
                          from a in book.BookAuthors
                          where a.Author.Equals(author)
                          select book).ToList();
            }

            return result;
        }
Beispiel #2
0
        public static List<Genre> GetAllGenresByAuthor(Author author)
        {
            List<Genre> result = new List<Genre>();

            using (var context = new BookDBDataContext())
            {
                result = (from genre in context.Genres
                          join bookGenre in context.BookGenres on genre.ID equals bookGenre.GenreID
                          join books in context.Books on bookGenre.BookID equals books.ID
                          join bookAuthors in context.BookAuthors on books.ID equals bookAuthors.BookID
                          join authors in context.Authors on bookAuthors.AuthorID equals authors.ID
                          where authors.FirstName.Equals(author.FirstName) && authors.LastName.Equals(author.LastName)
                          select genre).ToList();

                //var res = from a in context.Authors
                //          where a.FirstName == author
                //          from bookauth in a.BookAuthors
                //          from bookgenre in bookauth.Book.BookGenres
                //          select bookgenre.Genre.Name;
            }

            return result;
        }
Beispiel #3
0
        private static void AddAuthor(string firstName, string lastName, DateTime yearBorn, DateTime yearDied)
        {
            using (var context = new BookDBDataContext())
            {
                if (context.Authors.FirstOrDefault(author => author.FirstName == firstName && author.LastName == lastName) == null)
                {
                    Author temp = new Author()
                    {
                        FirstName = firstName,
                        LastName = lastName,
                        YearBorn = yearBorn,
                        YearDied = yearDied
                    };

                    context.Authors.InsertOnSubmit(temp);
                    context.SubmitChanges();
                }
            }
        }
Beispiel #4
0
 partial void DeleteAuthor(Author instance);
Beispiel #5
0
 partial void UpdateAuthor(Author instance);
Beispiel #6
0
 partial void InsertAuthor(Author instance);
Beispiel #7
0
        public void DeleteAllPhrases()
        {
            management.AuthorManagement.AddAuthor(author);

            Entity entityExpected = new Entity()
            {
                EntityName = "Mc donalds"
            };

            management.EntityManagement.AddEntity(entityExpected);
            Entity entity2 = new Entity()
            {
                EntityName = "Rappi"
            };

            management.EntityManagement.AddEntity(entity2);
            Entity entity = new Entity()
            {
                EntityName = "Coca cola"
            };

            management.EntityManagement.AddEntity(entity);
            Sentiment sentiment = new Sentiment()
            {
                SentimientText = "Me encanta",
                SentimentType  = Sentiment.TypeSentiment.Positive
            };

            management.SentimentManagement.AddSentiment(sentiment);
            Sentiment sentiment2 = new Sentiment()
            {
                SentimientText = "Me gusta",
                SentimentType  = Sentiment.TypeSentiment.Positive
            };

            management.SentimentManagement.AddSentiment(sentiment2);
            Phrase phrase = new Phrase()
            {
                TextPhrase   = "Me gusta Mc       donalds",
                PhraseDate   = DateTime.Now,
                Entity       = entityExpected,
                PhraseType   = Phrase.TypePhrase.Positive,
                PhraseAuthor = author
            };

            management.PhraseManagement.AddPhrase(phrase);
            Phrase phrase2 = new Phrase()
            {
                TextPhrase   = "No me gusta Rappi",
                PhraseDate   = DateTime.Now,
                Entity       = entity2,
                PhraseType   = Phrase.TypePhrase.Negative,
                PhraseAuthor = author
            };

            management.PhraseManagement.AddPhrase(phrase2);
            Author prueba = management.AuthorManagement.GetAuthor(author);

            management.PhraseManagement.DeletePhrasesOfAuthor(author);
            Assert.IsTrue(management.PhraseManagement.AllPhrases.Length == 0);
        }