public override async Task <StorageFile> GetImageAsync(DbBook book, DbBookContent content, int index, CancellationToken cancellationToken = default) { var data = DataContainer.Deserialize(content.Data); if (index < -1 || index >= data.Extensions.Length) { return(null); } var ext = ParseExtension(data.Extensions[Math.Max(0, index)]); var url = index == -1 ? $"https://t.nhentai.net/galleries/{data.MediaId}/thumb{ext}" : $"https://i.nhentai.net/galleries/{data.MediaId}/{index + 1}{ext}"; var response = await _http.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken); response.EnsureSuccessStatusCode(); return(new StorageFile { Name = url, MediaType = response.Content.Headers.ContentType?.MediaType, Stream = await response.Content.ReadAsStreamAsync() }); }
private void btnUpdateBook_Click(object sender, EventArgs e) { if (!TextFieldsAreValid()) { MessageBox.Show(this, "Alanları boş bırakmayınız", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } bool updateSuccessful = DbBook.UpdateBook(new Book() { id = Book.id, BookName = txtBoxBookName.Text, Price = txtBoxPrice.Text, WriterFullName = txtBoxWriterName.Text, Genre = cmbWriterGenre.SelectedItem.ToString() }); if (updateSuccessful) { MessageBox.Show(this, "Kitap güncellendi", "Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(this, "Kitap güncellenirken bir hata oldu", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public OperationResult <BookResponse> Execute(int id) { DbBook book = _bookDbContext.Books.FirstOrDefault(b => b.Id == id); DbAuthorBook author = _bookDbContext.Authors.FirstOrDefault(a => a.BookId == id); try { if (book == null) { throw new ArgumentException("Incorrect id"); } return(new OperationResult <BookResponse>() { IsSuccess = true, Body = _responseMapper.Map(book, author) }); } catch (ArgumentException exc) { return(new OperationResult <BookResponse>() { IsSuccess = false, ErrorMessages = { exc.Message } }); } }
public OperationResult <BookResponse> Execute(int id) { try { DbBook book = _context.Books.FirstOrDefault(x => x.Id == id); DbAuthorBook authorBook = _context.Authors.FirstOrDefault(x => x.BookId == id); if (authorBook != null) { _context.Authors.Remove(authorBook); } _context.SaveChanges(); if (book == null) { throw new ArgumentException("Model doesn't exist"); } _context.Books.Remove(book); _context.SaveChanges(); return(new OperationResult <BookResponse>() { IsSuccess = true }); } catch (ArgumentOutOfRangeException exc) { return(new OperationResult <BookResponse>() { IsSuccess = false, ErrorMessages = { exc.Message } }); } }
public BookScraperImageResult(DbBook book, DbBookContent content, int index) { _content = content; _index = index; Name = $"books/{book.Id}/contents/{content.Id}/pages/{index}"; }
private void btnSendBookCreate_Click(object sender, EventArgs e) { if (!TextFieldsAreValid()) { MessageBox.Show(this, "Lütfen alanları boş bırakmayınız", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } bool CreationSuccessful = DbBook.CreateBook(new Book() { Genre = txtBoxGenre.Text, BookName = txtBoxBookName.Text, WriterFullName = txtBoxWriterName.Text, Price = txtBoxPrice.Text, }); if (CreationSuccessful) { MessageBox.Show(this, "Kitap eklendi", "Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(this, "Kitap eklenirken bir hata oldu", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public BookService(DbBook db, IBusPublisher bus, IConfiguration configuration, ITenantAccessor tenantAccessor) { _db = db; _bus = bus; var settings = Settings.GetInstance(configuration, tenantAccessor.Tenant); FeatureAddTableAtuthor = new ValueGetter <bool>(() => settings.FeatureFlags.GetOrDefault(FeatureFlags.AddTableAtuthor)); }
public BookResponse Map([NotNull] DbBook book, DbAuthorBook authorBook) { return(new BookResponse() { Name = book.Name, Year = book.Year, Description = book.Description, Author = authorBook?.Author }); }
public static Book ToBusinessLogicModel(this DbBook dbBook) { return(new Book { Id = dbBook.Id, Title = dbBook.Title, Author = dbBook.Title, Year = dbBook.Year }); }
static string FormatBook(DbBook book) { var s = $"'{book.PrimaryName}' {string.Join(", ", book.Contents.Select(c => $"{c.Source}/{c.SourceId}"))}"; if (book.Id != null) { s = $"{book.Id} {s}"; } return(s); }
public async Task PopulateBooks() { var dbCtx = new LibraryDbContext(); var genre1 = new DbGenre() { Genre = "Education" }; var hashtagAgile = new DbHashtag() { Hastag = "#agile" }; var hashtagCosmos = new DbHashtag() { Hastag = "#cosmos" }; var hashtagCoding = new DbHashtag() { Hastag = "#coding" }; var book1 = new DbBook() { Title = "Clean Code: A Handbook of Agile Software Craftmanship", Author = "Robert C. Martin", Hashtags = new List <DbHashtag>() }; var book2 = new DbBook() { Title = "Cosmos", Author = "Carl Sagan", Hashtags = new List <DbHashtag>() }; dbCtx.Books.Add(book1); dbCtx.Books.Add(book2); dbCtx.Genres.Add(genre1); dbCtx.Hashtags.Add(hashtagAgile); dbCtx.Hashtags.Add(hashtagCosmos); dbCtx.Hashtags.Add(hashtagCoding); book1.Genre = genre1; book1.Hashtags.Add(hashtagAgile); book1.Hashtags.Add(hashtagCoding); book2.Genre = genre1; book1.Hashtags.Add(hashtagCosmos); await dbCtx.SaveChangesAsync(); }
public async Task DeleteAsync() { var client = Services.GetService <IElasticClient>(); var dummy = new DbBook { Contents = new[] { new DbBookContent() } }; var book = await client.Entry(dummy).CreateAsync(); var books = Services.GetService <IBookService>(); // delete book var deleteResult = await books.DeleteAsync(book.Id, new SnapshotArgs { Event = SnapshotEvent.BeforeDeletion, Reason = "this book sucks" }); Assert.That(deleteResult.IsT0, Is.True); // ensure deleted var getResult = await books.GetAsync(book.Id); Assert.That(getResult.IsT0, Is.False); // ensure snapshot var snapshots = Services.GetService <ISnapshotService>(); var snapshotResult = await snapshots.SearchAsync(ObjectType.Book, new SnapshotQuery { TargetId = book.Id, Limit = 1 }); Assert.That(snapshotResult.Total, Is.EqualTo(1)); Assert.That(snapshotResult.Items[0].Event, Is.EqualTo(SnapshotEvent.BeforeDeletion)); Assert.That(snapshotResult.Items[0].Reason, Is.EqualTo("this book sucks")); // delete nonexistent deleteResult = await books.DeleteAsync(book.Id, new SnapshotArgs()); Assert.That(deleteResult.IsT0, Is.False); }
private IBook ConvertToBook(DbBook book) { return(new Book { Title = book.Title, Author = book.Author, Code = book.Code, DaysForBorrowing = book.DaysForBorrowing, IsTaken = book.IsTaken, TakenByUser = book.TakenByUser, TakenWhen = book.TakenWhen, HasToBeReturned = book.HasToBeReturned, Genre = book.Genre?.Genre, Hashtags = book.Hashtags?.Select(h => h.Hastag).ToList() }); }
internal void UpdateValues(EntityContext context, DbBook dbItem, Book item) { dbItem.AdditionalInfo = item.AdditionalInfo; dbItem.Bookshelf = item.Bookshelf; dbItem.FlibustaUrl = item.FlibustaUrl; dbItem.ImageUrl = item.ImageUrl; dbItem.IsSynchronized = item.IsSynchronized; dbItem.LibRusEcUrl = item.LibRusEcUrl; dbItem.LiveLibUrl = item.LiveLibUrl; dbItem.Owner = item.Owner; dbItem.PageCount = item.PageCount; dbItem.Status = item.Status; dbItem.Title = item.Title; dbItem.Year = item.Year; context.SaveChanges(); }
public async Task DeleteAdditionalContent() { var client = Services.GetService <IElasticClient>(); var dummy = new DbBook { Contents = new[] { new DbBookContent(), new DbBookContent() } }; var book = await client.Entry(dummy).CreateAsync(); var books = Services.GetService <IBookService>(); // delete first content var deleteResult = await books.DeleteContentAsync(book.Id, book.Contents[0].Id, new SnapshotArgs { Event = SnapshotEvent.BeforeDeletion, Reason = "this content sucks" }); Assert.That(deleteResult.AsT0.Id, Is.EqualTo(book.Id)); // ensure snapshot var snapshots = Services.GetService <ISnapshotService>(); var snapshotResult = await snapshots.SearchAsync(ObjectType.Book, new SnapshotQuery { TargetId = book.Id, Limit = 1 }); Assert.That(snapshotResult.Total, Is.EqualTo(1)); Assert.That(snapshotResult.Items[0].Event, Is.EqualTo(SnapshotEvent.BeforeDeletion)); Assert.That(snapshotResult.Items[0].Reason, Is.EqualTo("this content sucks")); // book should not be deleted if there is still content remaining var getResult = await books.GetAsync(book.Id); Assert.That(getResult.AsT0.Contents, Has.Exactly(1).Items); Assert.That(getResult.AsT0.Contents[0].Id, Is.EqualTo(book.Contents[1].Id)); // second content should be remaining }
public DbBook Convert(IScraper scraper, IServiceProvider services) { var book = new DbBook().ApplyBase(ModelSanitizer.Sanitize(Book), services); book.Contents = (Contents ?? Enumerable.Empty <ContentAdaptor>()).ToArray(c => { var content = new DbBookContent().ApplyBase(ModelSanitizer.Sanitize(c.Content), services); content.PageCount = c.Pages; content.Source = scraper.Type; content.SourceId = c.Id; content.Data = c.Data; return(content); }); return(book); }
public static Book ToBook(this DbBook dbBook) { var book = new Book(dbBook.Title, dbBook.PageCount, dbBook.Status) { AdditionalInfo = dbBook.AdditionalInfo, Bookshelf = dbBook.Bookshelf, FlibustaUrl = dbBook.FlibustaUrl, Id = dbBook.Id, ImageUrl = dbBook.ImageUrl, IsSynchronized = dbBook.IsSynchronized, LibRusEcUrl = dbBook.LibRusEcUrl, LiveLibUrl = dbBook.LiveLibUrl, Owner = dbBook.Owner, Year = dbBook.Year, }; book.Authors.AddRange(dbBook.Authors.Select(x => x.ToAuthor())); return(book); }
public DbBook Convert(IScraper scraper, IServiceProvider services) { var book = new DbBook().ApplyBase(ModelSanitizer.Sanitize(Book), services); book.Contents = (Contents ?? Enumerable.Empty<ContentAdaptor>()).ToArray(c => { var content = new DbBookContent().ApplyBase(ModelSanitizer.Sanitize(c.Content), services); content.PageCount = c.Pages; content.Source = scraper.Type; content.SourceId = c.Id; content.Data = c.Data; content.IsAvailable = true; content.RefreshTime = DateTime.UtcNow; return content; }); return book; }
public int Create(BookCreateModel model) { var book = new DbBook(); book.ISBN = model.ISBN; book.Image = model.Image; book.Pages = model.Pages; book.PublishDate = model.PublishDate; book.Publisher = model.Publisher; book.Title = model.Title; var id = _bookRepository.Create(book); var author = new DbAuthor(); author.BookId = id; author.FirstName = model.AuthorFirstName; author.LastName = model.AuthorLastName; _authorRepository.Create(author); return(id); }
public void SetUp() { _bookRequest = new BookRequest() { Id = 1, Year = 123, Name = "af" }; _dbBook = new DbBook() { Id = 1, Year = 123, Name = "af" }; _bookResponse = new BookResponse() { Year = 123, Name = "af" }; }
public OperationResult <BookResponse> Execute( BookRequest book) { try { DbBook oldBook = _context.Books.FirstOrDefault(x => x.Id == book.Id); DbAuthorBook authorBook = _context.Authors.FirstOrDefault(x => x.BookId == book.Id); if (oldBook == null) { throw new ArgumentException("Old model doesn't exist"); } _context.Books.Remove(oldBook); _context.Books.Add(_dbBookMapper.Map(book)); if (authorBook != null) { _context.Authors.Remove(authorBook); } _context.Authors.Add(_dbAuthorBookMapper.Map(book)); _context.SaveChanges(); return(new OperationResult <BookResponse>() { IsSuccess = true }); } catch (Exception exc) { return(new OperationResult <BookResponse>() { IsSuccess = false, ErrorMessages = { exc.Message } }); } }
public SaveBookCommandHandler(DbBook db, IBusPublisher bus) { _db = db; _bus = bus; }
private void CustomerForm_Load(object sender, EventArgs e) { Books = DbBook.GetBooks(); BindingSource.DataSource = Books; gridViewBook.DataSource = BindingSource; }
private void BookCRUDForm_Load(object sender, EventArgs e) { Books = DbBook.GetBooks(); bindingSource.DataSource = Books; gridViewBook.DataSource = bindingSource; }
public BookQueryHandler(DbBook db) { _db = db; }
static void index(DbBook book, Dictionary <string, HashSet <DbBook> > dict, string key) { if (string.IsNullOrEmpty(key)) { return; } if (dict.TryGetValue(key, out var set)) { set.Add(book); } else { dict[key] = new HashSet <DbBook> { book } }; } foreach (var book in books) { var set = new HashSet <DbBook>(); union(set, primaryNames, book.PrimaryName); union(set, englishNames, book.EnglishName); var acSet = new HashSet <DbBook>(); foreach (var artist in book.TagsArtist ?? Array.Empty <string>()) { union(acSet, artistTags, artist); } foreach (var circle in book.TagsCircle ?? Array.Empty <string>()) { union(acSet, circleTags, circle); } set.IntersectWith(acSet); var merged = false; foreach (var other in set) { other.MergeFrom(book); if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation($"Merged book {FormatBook(book)} into similar book {FormatBook(other)} (dry)."); } merged = true; break; } // only add unique (not merged) books to results and indexes if (!merged) { results.Add(book); index(book, primaryNames, book.PrimaryName); index(book, englishNames, book.EnglishName); foreach (var artist in book.TagsArtist ?? Array.Empty <string>()) { index(book, artistTags, artist); } foreach (var circle in book.TagsCircle ?? Array.Empty <string>()) { index(book, circleTags, circle); } } } _count.Labels("dry").Inc(books.Length - results.Count); _logger.LogDebug($"Dry merging {books.Length} -> {results.Count} books took {measure}."); return(results.ToArray()); }
private void Add(EntityContext context, DbBook newDbItem) { context.DbBooks.Add(newDbItem); context.SaveChanges(); }