private void OnBookItemSelectedCommand(object obj) { BookEntity entity = obj as BookEntity; if (IsEditing) { entity.IsSelected = !entity.IsSelected; return; } else { if (entity == null || entity.CatalogList == null || entity.CatalogList.Count == 0) { ToastHeplper.ShowMessage("获取数据有误"); return; } if (string.IsNullOrEmpty(entity.LastReadChapterUrl)) { var item = entity.CatalogList.FirstOrDefault(); entity.LastReadChapterUrl = item.CatalogUrl;; entity.LastReadChapterName = item.CatalogName; } NavigationService.NavigateTo(typeof(BookContentPage), entity); } }
/// <summary> /// 存储 /// </summary> /// <param name="url"></param> /// <param name="fileBytes"></param> protected virtual void Save(string url, byte[] fileBytes) { var siteId = HttpUtility.ParseQueryString(url).Get("siteid").Convert <long>(); var query = new QueryInfo { IsReturnCount = false }; query.SetPageSize(1).Query <BookEntity>().Where(it => it.Site.Id == siteId && it.IsUsed == false) .Select(it => new object[] { it.Id, it.FileName }); var entity = Repository.GetEntities <BookEntity>(query)?.FirstOrDefault(); if (entity != null) { entity.FileByte = fileBytes; entity.IsUsed = true; entity.SetProperty(it => it.IsUsed).SetProperty(it => it.FileName); entity.SaveType = SaveType.Modify; } else { entity = new BookEntity(); entity.FileName = "/Files/Images/SiteBook/copy.jpg"; entity.FileByte = fileBytes; entity.IsUsed = true; entity.Site = new SiteEntity { Id = siteId }; entity.SaveType = SaveType.Add; } var unitofworks = BookDomainService.Handle(entity); Commit(unitofworks); }
//Add internal string AddSql(BookEntity data) { string colNames = ""; string colValue = ""; colNames += " Id "; colValue += " " + this.GetNewId() + " "; colNames += ",Name_Ar"; colValue += ",'" + data.Name_Ar + "'"; colNames += ",Name_En"; colValue += ",'" + data.Name_En + "'"; colNames += ",CatId"; colValue += "," + data.CatData.Id + ""; colNames += ",RowId"; colValue += ",'" + data.RowId + "'"; colNames += ",DateMade"; colValue += ",'" + this.dbHelper.GetServerDate().ToDateVal().FormatDate("MM/dd/yyyy HH:mm") + "'"; colNames += ",MadeById"; colValue += "," + data.MadeById + ""; //------------------------------- string sql = " INSERT INTO Books ( " + colNames + " ) VALUES ( " + colValue + " ) "; return(sql); }
public void Edit(BookEntity bookEntity) { var currentEntity = _bookContext.Books.FirstOrDefault(x => x.Id == bookEntity.Id); _bookContext.Books.Remove(currentEntity); _bookContext.Books.Add(bookEntity); }
public void Should_Validate_Book_Already_Published() { _publisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .WithPublisher(_publisher) .Build(); _book = new BookBuilder() .WithPublisher(_publisher) .Build(); var authorBook = new AuthorBookBuilder().WithAuthor(author).WithBook(_book).Build(); var authorsBook = new List <AuthorBookEntity> { authorBook }; _book.AuthorsBook = authorsBook; Action act = () => _bookPublishValidator.ValidatePublish(_book, _publisher); act.Should() .Throw <BusinessException>() .WithMessage($"Book ({_book.Id}) is already published!"); }
public void Create(BookEntity bookEntity) { var newBook = Clone(bookEntity); newBook.Id = bookList.Count; bookList.Add(newBook); }
public void InitData(object obj = null) { CancleHttpRequest(); BookEntity temp = obj as BookEntity; if (temp == null) { return; } this.CurrentBookEntity = null; this.CurrentBookEntity = temp; this.ContentTitle = CurrentBookEntity.BookName; if (CheckIfLoacalExist()) { CanDownLoad = false; } else { CanDownLoad = true; } }
public void Should_Validate_Publisher_Different_From_Authors() { _publisher = new PublisherBuilder().Build(); var anotherPublisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .WithPublisher(_publisher) .Build(); _book = new BookBuilder() .Build(); var authorBook = new AuthorBookBuilder().WithAuthor(author).WithBook(_book).Build(); var authorsBook = new List <AuthorBookEntity> { authorBook }; _book.AuthorsBook = authorsBook; Action act = () => _bookPublishValidator.ValidatePublish(_book, anotherPublisher); act.Should() .Throw <BusinessException>() .WithMessage($"{Environment.NewLine}The publisher of publication's book must be from one of the authors!"); }
public JsonResult InsertBook(BookEntity bookEntity) { DataResult result = null; if (string.IsNullOrEmpty(bookEntity.Name) && bookEntity.Price <= 0) { return(Json(new DataResult("10000", "输入信息不正确"))); } result = new DataResult(); var insertResult = this.bookBll.InsertBook(bookEntity); if (insertResult < 0) { return(Json(new DataResult("10001", "添加失败,请联系管理员"))); } else { result.code = "200"; result.errorMsg = "添加成功"; } return(Json(result)); }
public static BookEntity GetByTitle(string title) { BookEntity book = new BookEntity(); book = BookModel.GetByTitle(title); return(book); }
public static List <BookEntity> GetBookUpdateChapterList(string html) { List <BookEntity> list = new List <BookEntity>(); html = html.Replace("\r", "").Replace("\t", "").Replace("\n", ""); MatchCollection matches = Regex.Matches(html, "<div class=\"main-html\".*?class=\"xt1.*?</div>"); foreach (var item in matches) { MatchCollection matches2 = Regex.Matches(item.ToString(), "<a href.*?</a>"); BookEntity t_entity = new BookEntity(); t_entity.NewestChapterUrl = Regex.Match(matches2[0].ToString(), "(?<=&chapterurl=).*?(?=\")").ToString(); bool value = WebSet.CheckUrl(t_entity.NewestChapterUrl); if (!value) { continue; } t_entity.NewestChapterName = Regex.Match(matches2[0].ToString(), "(?<=alt=\").*?(?=\")").ToString(); // t_entity.ChapterName = Regex.Replace(matches2[0].ToString(), "<.*?>", "").ToString(); t_entity.LyWeb = Regex.Replace(matches2[1].ToString(), "<.*?>", "").ToString(); Match match2 = Regex.Match(item.ToString(), "(?<=<.*?class=\"xt1\">).*?(?=</div>)"); t_entity.UpdateTime = match2.ToString(); list.Add(t_entity); } return(list); }
private static BookDTO bookDTO(BookEntity bookEntity) => new BookDTO { Id = bookEntity.Id, Title = bookEntity.Title, Author = bookEntity.Author, Genre = bookEntity.Genre };
public IActionResult Edit(BookViewModel model) { var bookEntity = new BookEntity { Id = model.Id, Name = model.Name, Author = model.Author, Publisher = model.Publisher }; _bookService.Edit(bookEntity); #region Notlar //var updatedEntity = _bookService.Get(model.Id); //NOTE: Still need to improve somethings here and anywhere in project //var bookVM = new BookViewModel //{ // Id = updatedEntity.Id, // Name = updatedEntity.Name, // Author = updatedEntity.Author, // Publisher = updatedEntity.Publisher //}; //return View(bookVM); #endregion return(RedirectToAction(nameof(Index), "Book")); }
public BookEntity MapBook() { if (!_book.Number.ControlDigit.HasValue) { throw new ArgumentException( "must be filled with value", nameof(_book.Number.ControlDigit)); } var filled = !string.IsNullOrWhiteSpace(_book.BookType); var entity = new BookEntity { BookType = _book.BookType, ClosureDate = _book.ClosureDate, ControlDigit = _book.Number.ControlDigit.Value, CourtCode = _book.Number.CourtCode.ToUpper(), Filled = filled, Id = _book.Id.ToString("N"), Location = _book.Location, Number = _book.Number.Number, OpeningDate = _book.OpeningDate, Owner = _book.Owner }; return(entity); }
/// <summary> /// 根据id查询书籍 /// </summary> /// <param name="bookid">id</param> /// <returns></returns> public BookEntity GetBookByID(int bookid) { BookEntity bookEntity = this.dal.TEntity <BookEntity>() .GetById(bookid); return(bookEntity); }
public static BookEntity Update(this BookEntity original, IBookEditable update) { original.Author = update.Author; original.ReleaseDate = update.ReleaseDate; return(original); }
/// <summary> /// 新增书籍 /// </summary> /// <param name="bookEntity"></param> /// <returns></returns> public int InsertBook(BookEntity bookEntity) { var result = this.dal.TEntity <BookEntity>() .AsInsertable(bookEntity).ExecuteCommand(); return(result); }
public void Should_Validate_Publish_With_Excedent_Authors() { _publisher = new PublisherBuilder().Build(); var authorBuilder = new AuthorBuilder().WithPublisher(_publisher); var author = authorBuilder.Build(); var author2 = authorBuilder.Build(); var author3 = authorBuilder.Build(); var author4 = authorBuilder.Build(); _book = new BookBuilder().Build(); var authorBookBuilder = new AuthorBookBuilder().WithBook(_book); var authorBook = authorBookBuilder.WithAuthor(author).Build(); var authorBook2 = authorBookBuilder.WithAuthor(author2).Build(); var authorBook3 = authorBookBuilder.WithAuthor(author3).Build(); var authorBook4 = authorBookBuilder.WithAuthor(author4).Build(); var authorsBook = new List <AuthorBookEntity> { authorBook, authorBook2, authorBook3, authorBook4 }; _book.AuthorsBook = authorsBook; Action act = () => _bookPublishValidator.ValidatePublish(_book, _publisher); act.Should() .Throw <BusinessException>() .WithMessage($"Book can't have more than 3 authors!"); }
/// <summary> /// 修改书籍 /// </summary> /// <param name="bookEntity"></param> /// <returns></returns> public int UpdateBook(BookEntity bookEntity) { var result = this.dal.TEntity <BookEntity>() .AsUpdateable(bookEntity).UpdateColumns(book => new { book.Name, book.Price, }).ExecuteCommand(); return(result); }
public void CreateBook(CreateBookDto dto) { //数据验证 if (dto == null) { throw new ArgumentNullException(); } if (string.IsNullOrWhiteSpace(dto.Id) || string.IsNullOrWhiteSpace(dto.Name) || string.IsNullOrWhiteSpace(dto.Isbn) || dto.Price < 0) { throw new ArgumentException("数据不完整"); } var exists = InMemoryBookStorage.Books.Where(m => m.Isbn == dto.Isbn).Any(); if (exists) { throw new Exception($"ISBN:{dto.Isbn} 已存在"); } //转换为Entity对象,可使用Automapper转换 var entity = new BookEntity() { Id = dto.Id, Name = dto.Name, Isbn = dto.Isbn, Price = dto.Price, }; //保存到列表 InMemoryBookStorage.Books.Add(entity); }
public ActionResult NewBook(BookEntity bookEntity) { using (LibraryContext db = new LibraryContext()) { Book book = new Book(); int authorId = BookService.GetAuthorIdByName(bookEntity.Author); int genreId = BookService.GetGanreIdByName(bookEntity.Genre); if (authorId == 0) { Author newAuthor = new Author(); newAuthor.Name = bookEntity.Author; db.Authors.Add(newAuthor); db.SaveChanges(); } if (genreId == 0) { Genre newGenre = new Genre(); newGenre.name = bookEntity.Genre; db.Genres.Add(newGenre); db.SaveChanges(); } book = BookService.GetBook(bookEntity); db.Books.Add(book); db.SaveChanges(); } return(RedirectToAction("Index")); }
public List <BookEntity> GetList(int catId) { List <BookEntity> lst = null; DataTable table; string sql = this.GetSql(); sql += " WHERE CatId = " + catId + " "; table = this.dbHelper.retriveData(sql); if (table != null && table.Rows.Count > 0) { lst = new List <BookEntity>(); foreach (DataRow row in table.Rows) { BookEntity data = new BookEntity(); this.SetData(row, data); lst.Add(data); } } return(lst); }
public static bool DeleteHistory(string path, BookEntity entity) { bool result = true; using (var db = new SQLiteConnection(new SQLitePlatformWinRT(), path)) { db.CreateTable <BookEntity>(); db.RunInTransaction(() => { try { var temp = (from m in db.Table <BookEntity>() where m.BookID == entity.BookID select m ).FirstOrDefault(); if (temp != null) { db.Delete(temp); } } catch (Exception) { result = false; } }); } return(result); }
public int Add(BookEntity data) { string sql = this.AddSql(data); int x = this.dbHelper.whriteData(sql); return(x); }
public static bool InsertOrUpdateBookHistory(string path, BookEntity book) { bool result = true; using (var db = new SQLiteConnection(new SQLitePlatformWinRT(), path)) { db.CreateTable <BookEntity>(); db.RunInTransaction(() => { try { var temp = (from m in db.Table <BookEntity>() where m.BookID == book.BookID select m ).FirstOrDefault(); if (temp == null) { db.Insert(book); } else { book.Id = temp.Id; db.Update(book); } } catch (Exception) { result = false; } }); } return(result); }
/// <summary> /// Delete Book /// </summary> /// <param name="id"></param> /// <returns></returns> public static bool DeleteBook(int id) { var rep = ApiClient.DeleteAsync(BaseUrl, "/api/Books/" + id, null, null, cancellationToken); var result = new BookEntity(); return(rep.Result.Success); }
public int AddBook(BookInfo BookInfo) { var book = new BookEntity() { Author = BookInfo.Author, Category = BookInfo.Category, Count = BookInfo.Count, CreateDate = BookInfo.CreateDate, CreateUser = BookInfo.CreateUser, LastModifyDate = BookInfo.LastModifyDate, LastModifyUser = BookInfo.LastModifyUser, Name = BookInfo.Name, Note = BookInfo.Note, Number = BookInfo.Number, Press = BookInfo.Press, Price = BookInfo.Price, Style = BookInfo.Style, Type = BookInfo.Type, Year = BookInfo.Year }; book.CreateDate = DateTime.Now; _DBBook.Add(book); _DBBookItem.Add(new BookItemEntity() { BookID = book.ID, Status = (int)BookStatus.正常, BarCode = BookInfo.BarCode }); return(book.ID); }
public static BookEntity GetBook(string path, BookEntity entity) { BookEntity result = null; using (var db = new SQLiteConnection(new SQLitePlatformWinRT(), path)) { db.CreateTable <BookEntity>(); db.RunInTransaction(() => { try { var temp = (from m in db.Table <BookEntity>() where m.BookID == entity.BookID select m ).FirstOrDefault(); result = temp; } catch (Exception) { result = null; } }); } return(result); }
public bool Contains(BookEntity bookEntity) { return(this.dbContext.Books.Any(a => a.Name == bookEntity.Name && a.Year == bookEntity.Year && a.Cost == bookEntity.Cost)); }
public void PopulateBookEntityWithBookDTO() { BookDTO bookDTO = new BookDTO { RowKey = "9780132350884", JacketUrl = "https://edel-images.azureedge.net/ea/PEAR/images/jacket_covers/original/0132350882_938ba.jpg", Title = "Clean Code: A Handbook of Agile Software Craftsmanship", Series = "Robert C. Martin Series", Author = "Robert C.Martin", Price = 49.99 }; // Create the bookEntity from the bookDTO BookEntity bookEntity = new BookEntity(bookDTO); // Ensure the items match up Assert.Equal("partition1", bookEntity.PartitionKey); Assert.Equal(bookDTO.RowKey, bookEntity.RowKey); Assert.Equal(bookDTO.JacketUrl, bookEntity.JacketUrl); Assert.Equal(bookDTO.Title, bookEntity.Title); Assert.Equal(bookDTO.Series, bookEntity.Series); Assert.Equal(bookDTO.Author, bookEntity.Author); Assert.Equal(bookDTO.Price, bookEntity.Price); Assert.Equal("*", bookEntity.ETag); }
public void GivenThatBookHasOneAuthor_WhenAccessingAdapterAuthors_ThenAdapterHasOneAuthor() { var entity = new BookEntity { Authors = new[] { "Joakim Skoog" } }; var adapter = new BookEntityAdapter(entity); Assert.AreEqual(entity.Authors.Count(), adapter.Authors.Count); }
public void GivenThatBookHasName_WhenAccessingAdapterName_ThenAdapterNameIsSameAsBook() { var entity = new BookEntity { Name = "bookName" }; var adapter = new BookEntityAdapter(entity); Assert.AreEqual(entity.Name, adapter.Name); }
public void GivenThatBookHasNumberOfPages_WhenAccessingAdapterNumberOfPages_ThenAdapterNumberOfPagesIsSameAsBook() { var entity = new BookEntity { NumberOfPages = 312 }; var adapter = new BookEntityAdapter(entity); Assert.AreEqual(entity.NumberOfPages, adapter.NumberOfPages); }
public void GivenThatBookHasIsbn_WhenAccessingAdapterIsbn_ThenAdapterIsbnIsSameAsBook() { var entity = new BookEntity { ISBN = "isbn" }; var adapter = new BookEntityAdapter(entity); Assert.AreEqual(entity.ISBN, adapter.ISBN); }
public void GivenThatBookHasHardcoverMediaType_WhenAccessingAdapterMediaType_ThenAdapterMediaTypeIsHardcover() { var entity = new BookEntity {MediaType = MediaTypeEntity.Hardcover}; var adapter = new BookEntityAdapter(entity); Assert.AreEqual(MediaType.Hardcover, adapter.MediaType); }
public void GivenThatBookHasCountry_WhenAccessingAdapterCountry_ThenAdapterCountryIsSameAsBook() { var entity = new BookEntity { Country = "Sweden" }; var adapter = new BookEntityAdapter(entity); Assert.AreEqual(entity.Country, adapter.Country); }
public BookEntityAdapter(BookEntity bookEntity) { if (bookEntity == null) throw new ArgumentNullException(nameof(bookEntity)); _bookEntity = bookEntity; }
//Delete public void Delete(BookEntity BookEntity) { db.BookEntity.DeleteOnSubmit(BookEntity); }
// Create public void Create(BookEntity BookEntity) { db.BookEntity.InsertOnSubmit(BookEntity); }
public void GivenThatBookHasOnePovCharacter_WhenAccessingPovCharacters_ThenAdapterPovCharactersContaineOneCharacter() { var entity = new BookEntity { PovCharacters = new List<CharacterEntity> { new CharacterEntity { Id = 1, Name = "characterName" } } }; var adapter = new BookEntityAdapter(entity); Assert.AreEqual(entity.PovCharacters.Count, adapter.POVCharacters.Count); }
public void GivenThatBookHasReleaseDate_WhenAccessingAdapterReleaseDate_ThenAdapterReleaseDateIsSameAsBook() { var entity = new BookEntity { ReleaseDate = new DateTime(2000, 1, 1) }; var adapter = new BookEntityAdapter(entity); Assert.AreEqual(entity.ReleaseDate, adapter.Released); }
public void GivenThatBookHasPublisher_WhenAccessingAdapterPublisher_ThenAdapterPublisherIsSameAsBook() { var entity = new BookEntity { Publisher = "publisher" }; var adapter = new BookEntityAdapter(entity); Assert.AreEqual(entity.Publisher, adapter.Publisher); }