Пример #1
0
        // Custom

        public BookDetailsDTO GetBookDetails(int id)
        {
            using (var conn = DbConnection())
            {
                BookDetailsDTO book = null;
                if (conn.State == ConnectionState.Open)
                {
                    using (var cmd = new SqlCommand("Book_SelectByDetails", conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Book_Id", id);
                        var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                        if (reader.Read())
                        {
                            book = new BookDetailsDTO()
                            {
                                Title            = (string)reader["Title"],
                                Genre            = (string)reader["Genre"],
                                Publication_Date = (DateTime)reader["Publication_Date"],
                                Description      = (string)reader["Description"],
                                Price            = (decimal)reader["Price"],
                                Author           = (string)reader["Name"]
                            };
                        }
                    }
                }
                else
                {
                    BadConnection();
                }
                return(book);
            }
        }
 static internal AvailabilityDetailsDTO FromAvailability(Availability availabilty)
 {
     return(new AvailabilityDetailsDTO
     {
         BookDetails = BookDetailsDTO.FromBook(availabilty.Book),
         IsAvailable = availabilty.Reservation == null,
     });
 }
Пример #3
0
        public BookDetailsDTO Get(int id)
        {
            Book           Book   = IBookRepository.Get(id);
            BookDetailsDTO MyBook = new BookDetailsDTO()
            {
                Name            = Book.Name,
                Popularity      = Book.Popularity,
                PublicationYear = Book.PublicationYear
            };
            IEnumerable <BookWriter> MyBookWriters = IBookWriterRepository.GetAll().Where(x => x.BookId == Book.Id);

            if (MyBookWriters != null)
            {
                List <string> BookWriterList = new List <string>();
                foreach (BookWriter MyBookWriter in MyBookWriters)
                {
                    Writer MyWriter = IWriterRepository.GetAll().SingleOrDefault(x => x.Id == MyBookWriter.Id);
                    BookWriterList.Add(MyWriter.Name);
                }
                MyBook.WriterName = BookWriterList;
            }

            IEnumerable <BookLibrary> MyLibraryBooks = IBookLibraryRepository.GetAll().Where(x => x.BookId == Book.Id);

            if (MyLibraryBooks != null)
            {
                List <string> LibraryBookList = new List <string>();
                foreach (BookLibrary MyLibraryBook in MyLibraryBooks)
                {
                    Library MyLibrary = ILibraryRepository.GetAll().SingleOrDefault(x => x.Id == MyLibraryBook.Id);
                    LibraryBookList.Add(MyLibrary.Name);
                }
                MyBook.LibraryName = LibraryBookList;
            }

            IEnumerable <BookPublisher> MyPublisherBooks = IBookPublisherRepository.GetAll().Where(x => x.BookId == Book.Id);

            if (MyPublisherBooks != null)
            {
                List <string> PublisherBookList = new List <string>();
                foreach (BookPublisher MyPublisherBook in MyPublisherBooks)
                {
                    Publisher MyPublisher = IPublisherRepository.GetAll().SingleOrDefault(x => x.Id == MyPublisherBook.Id);
                    PublisherBookList.Add(MyPublisher.Name);
                }
                MyBook.PublisherName = PublisherBookList;
            }
            return(MyBook);
        }