public void EnsureBookFile(AuthorResource author, int bookId, string foreignEditionId, Quality quality) { var result = Books.GetBooksInAuthor(author.Id).Single(v => v.Id == bookId); // if (result.BookFile == null) if (true) { var path = Path.Combine(AuthorRootFolder, author.AuthorName, "Track.mp3"); Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllText(path, "Fake Track"); Commands.PostAndWait(new ManualImportCommand { Files = new List <ManualImportFile> { new ManualImportFile { Path = path, AuthorId = author.Id, BookId = bookId, ForeignEditionId = foreignEditionId, Quality = new QualityModel(quality) } } }); Commands.WaitAll(); var track = Books.GetBooksInAuthor(author.Id).Single(x => x.Id == bookId); // track.BookFileId.Should().NotBe(0); } }
public async Task <IActionResult> UpdateAuthor(int authorId, [FromBody] AuthorResource authorResource) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var author = await authorsRepository.GetAuthorByIdAsync(authorId); if (author == null) { return(NotFound()); } mapper.Map <AuthorResource, Author>(authorResource, author); author.LastUpdate = DateTime.Now; await unitOfWork.CompleteAsync(); author = await authorsRepository.GetAuthorByIdAsync(author.Id); var result = mapper.Map <Author, AuthorResource>(author); return(Ok(result)); } catch (System.Exception ex) { return(BadRequest(ex.Message)); } }
public static List <AuthorResource> AuthorBookResource(this IEnumerable <Author> entity) { var listOfAuthorResource = new List <AuthorResource>(); //if (author != null) // entities = entities.Where(e => e.Author.Contains(author)); foreach (var author in entity) { var resource = new AuthorResource(); resource.Id = author.Id; resource.FullName = author.FullName; resource.Age = author.Age; resource.Email = author.Email; resource.Books = new List <BookAuthorResource>(); foreach (var book in author.Books) { resource.Books.Add(new BookAuthorResource { Id = book.Id, Title = book.Title, Description = book.Description, IsAvailable = book.IsAvailable, }); } listOfAuthorResource.Add(resource); } return(listOfAuthorResource); }
public void should_be_able_to_add_to_blocklist() { _author = EnsureAuthor("14586394", "43765115", "Andrew Hunter Murray"); Blocklist.Post(new BlocklistResource { AuthorId = _author.Id, SourceTitle = "Blacklist - Book 1 [2015 FLAC]" }); }
public async Task <ActionResult <AuthorResource> > GetAuthors(int id) { var authorFromRepo = await _authorRepository.Get(id); if (authorFromRepo == null) { return(NotFound()); } //var books = _bookRepository.Get().Result.Where(e => bookModel.AuthorIds.Contains(e.Id)).ToList(); var authorResource = new AuthorResource { Id = authorFromRepo.Id, FullName = authorFromRepo.FullName, Age = authorFromRepo.Age, Email = authorFromRepo.Email //BookTitles = authorFromRepo.Books.Select(e => e.Title).ToList() }; return(Ok(authorResource)); }
public async Task <IActionResult> AddAuthor([FromBody] AuthorResource authorResource) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var author = mapper.Map <AuthorResource, Author>(authorResource); author.LastUpdate = DateTime.Now; authorsRepository.AddAuthorAsync(author); await unitOfWork.CompleteAsync(); var newAuthor = await authorsRepository.GetAuthorByIdAsync(author.Id); return(Ok(mapper.Map <Author, AuthorResource>(newAuthor))); } catch (System.Exception ex) { return(BadRequest(ex.Message)); } }