public static bool HasMatchingValues(BookListView bookListView, Book book) { return bookListView.Id == book.Id && bookListView.Image.Id == book.Id && bookListView.Title == book.Title && bookListView.Rating == book.Rating; }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Model.Book model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into book("); strSql.Append("DUserId,BookTime,ProjectId,ProjectName,UserName,IsVerification)"); strSql.Append(" values ("); strSql.Append("@DUserId,@BookTime,@ProjectId,@ProjectName,@UserName,@IsVerification)"); MySqlParameter[] parameters = { new MySqlParameter("@DUserId", MySqlDbType.VarChar, 255), new MySqlParameter("@BookTime", MySqlDbType.DateTime), new MySqlParameter("@ProjectId", MySqlDbType.Int32, 11), new MySqlParameter("@ProjectName", MySqlDbType.VarChar, 255), new MySqlParameter("@UserName", MySqlDbType.VarChar, 255), new MySqlParameter("@IsVerification", MySqlDbType.Bit) }; parameters[0].Value = model.DUserId; parameters[1].Value = model.BookTime; parameters[2].Value = model.ProjectId; parameters[3].Value = model.ProjectName; parameters[4].Value = model.UserName; parameters[5].Value = model.IsVerification; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected void btnSubmit_Click(object sender, EventArgs e) { Model.Book u = new Model.Book { Book_Title = this.txtTitle.Text, Book_Content = this.txtContent.Text, Book_Image = upFileName(this.FileUpload1, "../../upload/Book/"), Book_Price = float.Parse(this.txtPrice.Text), Book_publish = this.txtpublish.Text, Book_Author = this.txtAuthor.Text, Book_Intro = this.txtIntro.Text, Book_Catalog = this.txtCatalog.Text, Book_Read = this.txtRead.Text, }; var res = BookSvc.Add(u); ReturnMsg rm = res > 0 ? new ReturnMsg() { Code = StatusCode.OK, Message = "新增用户信息成功", Data = null } : new ReturnMsg() { Code = StatusCode.Error, Message = "新增用户信息失败", Data = null }; Session["Msg"] = rm; //用于传递执行信息的 Response.Redirect("Book_List.aspx"); }
public BookListView(Book book) { this.Id = book.Id; this.Image = new ImageDisplayModel(book.Id) {Height = 100, Width = 100}; this.Title = book.Title; this.Rating = book.Rating; }
public static Book CreateNew(SourceDirectory sourceDirectory, string file) { var book = new Book { SourceDirectory = new SourceDirectory { Id = sourceDirectory.Id, EntityState = EntityState.Unchanged, SourceDirectoryUrl = sourceDirectory.SourceDirectoryUrl }, CoverImage = CoverImageFactory.CreateEmpty(), BookFile = BookFileFactory.CreateNew(file), Title = Path.GetFileNameWithoutExtension(file), Abstract = Empty }; book.SourceDirectory.EntityState = EntityState.Unchanged; book.BookFile.Book = book; book.BookHistory = new BookHistory {Book = book}; book.Authors = new HashSet<Author>(); book.Publishers = new HashSet<Publisher>(); book.BookMarks = new HashSet<BookMark>(); book.Notes = new HashSet<Note>(); book.SourceDirectoryId = sourceDirectory.Id; return book; }
public static IEnumerable<Book> CreateBooks(int number, BookStatus status, Genre genre = null) { for (int i = 0; i < number; i++) { var book = new Book("blah", new[] {"jim", "John", "Jackie"}, "crap", genre ??new Genre("gumbo"), status, new[] {(byte) 1}); yield return book; } }
// TODO - Am I happy with view model inheritance? public ViewBookViewModel(Book book, IEnumerable<Book> allBooksForSameGenre) : base(book) { this.Review_Html = book.Review; // TODO - Should this mapping occur inside the view model (taking the dependency) or inside the controller? this.RelatedBooks = allBooksForSameGenre .Where(b => b.Id != book.Id) .Select(r => new BookListView(r)); }
public Selection(Book book, SelectionScope scope, List<int> indexes) { this.book = book; this.scope = scope; if (indexes != null) { this.indexes = new List<int>(indexes); } }
/// <summary> /// 获得数据列表 /// </summary> public List <Model.Book> DataTableToList(DataTable dt) { List <Model.Book> modelList = new List <Model.Book>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Model.Book model; for (int n = 0; n < rowsCount; n++) { model = new Model.Book(); if (dt.Rows[n]["Id"].ToString() != "") { model.Id = int.Parse(dt.Rows[n]["Id"].ToString()); } model.Title = dt.Rows[n]["Title"].ToString(); model.Author = dt.Rows[n]["Author"].ToString(); if (dt.Rows[n]["PublisherId"].ToString() != "") { int PublisherId = int.Parse(dt.Rows[n]["PublisherId"].ToString()); model.Publisher = publisherServices.GetModel(PublisherId); } if (dt.Rows[n]["PublishDate"].ToString() != "") { model.PublishDate = DateTime.Parse(dt.Rows[n]["PublishDate"].ToString()); } model.ISBN = dt.Rows[n]["ISBN"].ToString(); if (dt.Rows[n]["WordsCount"].ToString() != "") { model.WordsCount = int.Parse(dt.Rows[n]["WordsCount"].ToString()); } if (dt.Rows[n]["UnitPrice"].ToString() != "") { model.UnitPrice = decimal.Parse(dt.Rows[n]["UnitPrice"].ToString()); } model.ContentDescription = dt.Rows[n]["ContentDescription"].ToString(); model.AurhorDescription = dt.Rows[n]["AurhorDescription"].ToString(); model.EditorComment = dt.Rows[n]["EditorComment"].ToString(); model.TOC = dt.Rows[n]["TOC"].ToString(); if (dt.Rows[n]["CategoryId"].ToString() != "") { int CategoryId = int.Parse(dt.Rows[n]["CategoryId"].ToString()); model.Category = categoryServices.GetModel(CategoryId); } if (dt.Rows[n]["Clicks"].ToString() != "") { model.Clicks = int.Parse(dt.Rows[n]["Clicks"].ToString()); } modelList.Add(model); } } return(modelList); }
public void WhenRequestingABookReview_AndTheSystemContainsBooks_WithDifferentGenres() { var retriever = MockRepository.GenerateMock<IBookRetriever>(); var endpoint = new ViewEndpoint(retriever); book = BookTestingHelper.GetBook(rating: 4); retriever.Stub(r => r.GetById(book.Id)).Return(book); SetupBookForSameGenreIncludingReviewBook(); retriever.Stub(r => r.GetReviewedBooks(book.Genre.Id)).Return(allBooksForSameGenre); viewModel = endpoint.Get(new ViewBookLinkModel { Id = book.Id }); }
private Book GetBookThatExistsInSession(byte[] image = null) { var genre = new Genre("a"); var book = new Book("blah", new[] {"me", "you", "him"}, "descy", GetGenreThatExistsInSession(), BookStatus.CurrentlyReading, image ?? new[] { (byte)1 }); book.Id = "books/999"; Session.Store(genre); Session.Store(book); Session.SaveChanges(); return book; }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); UserManager userManager = new UserManager(); if (userManager.validateUserLogin()) { int bookId = Convert.ToInt32((context.Request["bookId"])); BookManager bookManager = new BookManager(); Model.Book bookModel = bookManager.GetModel(bookId); if (bookModel != null) { int userId = ((Model.User)context.Session["userInfo"]).Id; CartManager cartManager = new CartManager(); //Model.Book bookModel = bookManager.GetModel(bookId); Model.Cart cartModel = cartManager.GetModel(userId, bookId); if (cartModel != null) { cartModel.Count = cartModel.Count + 1; cartManager.Update(cartModel); } else { Cart modelCart = new Cart(); modelCart.Count = 1; modelCart.Book = bookModel; modelCart.User = (User)context.Session["userInfo"]; cartManager.Add(modelCart); } context.Response.Write("Success"); } else { context.Response.Write("No Such Stuff"); } context.Response.Write("Success"); } else { context.Response.Write("Please Login"); } }
private void PersistBooks(IEnumerable<GenreDto> genreDtos) { var books = sqlImporter.ImportBooks(); foreach (var dto in books) { var genreName = GetGenreName(genreDtos, dto); var genre = session.Query<Genre>().Single(g => g.Name == genreName); var status = (BookStatus)Enum.Parse(typeof(BookStatus), dto.Status); var b = new Book(dto.Title, dto.Authors, dto.Description, genre, status, dto.ImageData); if(dto.Rating > 0) { b.Rating = dto.Rating; } session.Store(b); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.Book DataRowToModel(DataRow row) { Model.Book model = new Model.Book(); if (row != null) { if (row["BookId"] != null && row["BookId"].ToString() != "") { model.BookId = int.Parse(row["BookId"].ToString()); } if (row["DUserId"] != null) { model.DUserId = row["DUserId"].ToString(); } if (row["BookTime"] != null && row["BookTime"].ToString() != "") { model.BookTime = DateTime.Parse(row["BookTime"].ToString()); } if (row["ProjectId"] != null && row["ProjectId"].ToString() != "") { model.ProjectId = int.Parse(row["ProjectId"].ToString()); } if (row["ProjectName"] != null) { model.ProjectName = row["ProjectName"].ToString(); } if (row["UserName"] != null) { model.UserName = row["UserName"].ToString(); } if (row["IsVerification"] != null && row["IsVerification"].ToString() != "") { if ((row["IsVerification"].ToString() == "1") || (row["IsVerification"].ToString().ToLower() == "true")) { model.IsVerification = true; } else { model.IsVerification = false; } } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.Book model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update book set "); strSql.Append("DUserId=@DUserId,"); strSql.Append("BookTime=@BookTime,"); strSql.Append("ProjectId=@ProjectId,"); strSql.Append("ProjectName=@ProjectName,"); strSql.Append("UserName=@UserName,"); strSql.Append("IsVerification=@IsVerification"); strSql.Append(" where BookId=@BookId"); MySqlParameter[] parameters = { new MySqlParameter("@DUserId", MySqlDbType.VarChar, 255), new MySqlParameter("@BookTime", MySqlDbType.DateTime), new MySqlParameter("@ProjectId", MySqlDbType.Int32, 11), new MySqlParameter("@ProjectName", MySqlDbType.VarChar, 255), new MySqlParameter("@UserName", MySqlDbType.VarChar, 255), new MySqlParameter("@IsVerification", MySqlDbType.Bit), new MySqlParameter("@BookId", MySqlDbType.Int32, 11) }; parameters[0].Value = model.DUserId; parameters[1].Value = model.BookTime; parameters[2].Value = model.ProjectId; parameters[3].Value = model.ProjectName; parameters[4].Value = model.UserName; parameters[5].Value = model.IsVerification; parameters[6].Value = model.BookId; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.Book GetModel(int BookId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select BookId,DUserId,BookTime,ProjectId,ProjectName,UserName,IsVerification from book "); strSql.Append(" where BookId=@BookId"); MySqlParameter[] parameters = { new MySqlParameter("@BookId", MySqlDbType.Int32) }; parameters[0].Value = BookId; Model.Book model = new Model.Book(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 根据书籍id号得到书籍结果 /// </summary> /// <param name="book_id"></param> /// <returns></returns> public Model.Book GetSingleBook(string book_id) { string strSql = "select * from [Book] where b_id=@book_id"; SqlParameter[] parameters ={ new SqlParameter ("@book_id",SqlDbType .VarChar,50), }; parameters[0].Value = book_id; Model.Book model = new Model.Book(); DataTable dt = SqlDbHelper.ExecuteDataTable(strSql.ToString(), CommandType.Text, parameters); if (dt.Rows.Count > 0) { model.Id = dt.Rows[0].ItemArray[0].ToString(); model.Name = dt.Rows[0].ItemArray[1].ToString(); model.Author = dt.Rows[0].ItemArray[2].ToString(); model.Publisher = dt.Rows[0].ItemArray[3].ToString(); model.Amount = dt.Rows[0].ItemArray[4].ToString(); } return model; }
public static void ShouldHaveDetailsFor(this UpdateBookViewModel model, Book book) { HasMatchingAuthors(model, book); Assert.AreEqual(book.Review, model.Description_BigText); Assert.AreEqual(book.Genre.Name, model.SelectedGenre); Assert.AreEqual(book.Genre.Id, model.Genre); Assert.AreEqual(book.Id, model.Id); Assert.AreEqual(book.Status, model.BookStatus); Assert.AreEqual(book.Title, model.Title); }
private static void HasMatchingAuthors(UpdateBookViewModel model, Book book) { Assert.AreEqual(model.Authors.Count(), book.Authors.Count()); Assert.That(book.Authors.All(a => model.Authors.Any(x => a == x)), Is.True); }
/// <summary> /// Создание книги /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bookRadioButton_CheckedChanged(object sender, EventArgs e) { if (!bookRadioButton.Checked) return; ILiterarySource source; var book = new Book() { Author = "Бычкова С.М", Title = "Планирование в аудите", StatementOfResponsibility = "С.М. Бычкова, А.В.Газорян", YearOfManufacture = 2007, CountOfPages = 263 }; source = book; source.GetDescription(); LiterarySources.Rows.Add("Book", source.GetDescription()); DescriptionSourceDataGridView.Refresh(); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.Book model) { return(dal.Add(model)); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Model.Book model) { dal.Update(model); }