private IEnumerable <BookDto> ConvertListPocoBookToListDtoBook(IEnumerable <Book> bookList) { List <BookDto> booksList = new List <BookDto>(); foreach (Book book in bookList) { var bookDto = ConvertPocoBookToDtoBook(book); using (_entitiesContext = new GogolStoreEntities()) { IQueryable <byte[]> photos = _entitiesContext .BooksPhotoes .Where(x => x.BOOK_ID == bookDto.ISBN).Select(x => x.PHOTO); bookDto.Photos = new List <String>(); foreach (var photo in photos) { bookDto.Photos.Add(Convert.ToBase64String(photo)); } } booksList.Add(bookDto); } return(booksList); }
private void AddNewPublisher(string name) { var dedicatedContext = new GogolStoreEntities(); var addedPublisher = dedicatedContext.Publishers.Add(new Publisher { Name = name, Country = "Ukraine" }); //TODO: Country hardcode - Temp dedicatedContext.SaveChanges(); }
public IEnumerable <BookDto> GetFilteredBooks(FilterRequest filters) { using (_entitiesContext = new GogolStoreEntities()) { List <Book> filteredBooks = null; if (filters.authors != null) { if (filters.authors.Count != 0) { filteredBooks = _entitiesContext.Books.Where( x => filters.authors.Contains(x.Author.Name)).ToList(); } } if (filters.publishers != null) { if (filters.publishers.Count != 0) { filteredBooks = filteredBooks != null ? filteredBooks.Where( x => filters.publishers.Contains(x.Publisher.Name)).ToList() : _entitiesContext.Books.Where( x => filters.publishers.Contains(x.Publisher.Name)).ToList(); } } if (filters.categories != null) { if (filters.categories.Count != 0) { filteredBooks = filteredBooks != null ? filteredBooks.Where( x => filters.categories.Contains(x.Category.Name)).ToList() : _entitiesContext.Books.Where( x => filters.categories.Contains(x.Category.Name)).ToList(); } } return(ConvertListPocoBookToListDtoBook(filteredBooks)); } }
public BooksRepository() { _entitiesContext = new GogolStoreEntities(); }