public void DeleteReaderUsingSurnameTest() { Assert.IsTrue(ReaderService.AddReader("Sharoon", "Steel")); //delete to restore original db Assert.IsTrue(ReaderService.DeleteReader("Sharoon", "Steel")); }
public void AddReaderToDatabaseTest() { Assert.IsTrue(ReaderService.AddReader("Sharoon", "Steel")); //delete to restore original db Assert.IsTrue(ReaderService.DeleteReader("Sharoon", "Steel")); }
public void AddReaderToDatabaseTest() { Assert.IsTrue(ReaderService.AddReader("Sharoon", "Steel")); Assert.AreEqual(ReaderService.GetAllReadersNumber(), 6); //delete to restore original db Assert.IsTrue(ReaderService.DeleteReader("Sharoon", "Steel")); }
private void AddReader() { bool added = ReaderService.AddReader(FName, LName); if (added) { actionText = "Reader Added"; } else { actionText = "Reader already exists in the database"; } MessageBoxShowDelegate(ActionText); }
public void AddEventToDatabaseTest() { Assert.IsTrue(ReaderService.AddReader("Britney", "Spears")); Reader reader = ReaderService.GetReader("Britney", "Spears"); Assert.IsTrue(BookService.AddBook("Awesome Author", "Awesome Title", 2020, "Cute", 10)); Book book = BookService.GetBook("Awesome Title", "Awesome Author"); Assert.IsTrue(EventService.AddEvent(DateTime.Now, true, book.book_id, reader.reader_id)); //delete to restore original db Assert.IsTrue(EventService.DeleteEvent(reader.reader_id, book.book_id)); Assert.IsTrue(ReaderService.DeleteReader(reader.reader_f_name, reader.reader_l_name)); Assert.IsTrue(BookService.DeleteBook(book.title)); }
public void UpdateReaderNameTest() { Assert.IsTrue(ReaderService.AddReader("Britney", "Spears")); Reader reader = ReaderService.GetReader("Britney", "Spears"); Assert.IsTrue(ReaderService.UpdateReader(reader.reader_id, "Ann", "Test")); Reader reader1 = ReaderService.GetReader("Britney", "Spears"); Assert.IsNull(reader1); Reader reader2 = ReaderService.GetReader("Ann", "Test"); Assert.IsNotNull(reader2); //restore original db Assert.IsTrue(ReaderService.DeleteReader("Ann", "Test")); }
public IHttpActionResult Create(ReaderModel reader) { try { ReaderService readerService = new ReaderService(); Reader dbBook = new Reader(); reader.CopyValuesToEntity(dbBook); readerService.AddReader(dbBook); // return the newly created Book return(Ok(dbBook)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Post(ReaderModel reader) { try { ReaderService readerService = new ReaderService(); Reader dbReader = new Reader(); reader.CopyValuesToEntity(dbReader); readerService.AddReader(dbReader); // return the newly created Reader ReaderModel newReader = new ReaderModel(dbReader); return(Ok(newReader)); } catch (Exception ex) { return(BadRequest(ex.GetBaseException().Message)); } }
/// <summary> /// 会员添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { //[1]数据验证 //[2]封装对象 Readers objReader = new Readers() { ReaderName = this.txtReaderName.Text.Trim(), ReadingCard = this.txtReadingCard.Text.Trim(), Gender = this.rdoMale.Checked ? "男" : "女", RoleId = Convert.ToInt32(this.cboReaderRole.SelectedValue), PostCode = this.txtPostcode.Text.Trim(), PhoneNumber = this.PhoneNumber.Text.Trim(), ReaderAddress = this.txtAddress.Text.Trim(), ReaderImage = this.pbReaderPhoto.Image != null ? new Common.SerializeObjectToString().SerializeObject(this.pbReaderPhoto.Image) : "", IDCard = this.txtIdCard.Text.Trim() }; //调用底层 try { readerService.AddReader(objReader); MessageBox.Show("添加成功", "添加提示"); //清空数据 this.pbReaderImg.Image = null; this.rdoMale.Checked = true; this.cboReaderRole.SelectedIndex = -1; //清空text Box foreach (Control item in this.tabPage2.Controls) { if (item is TextBox) { item.Text = ""; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void DeleteReaderAndHisEventsTest() { Assert.IsTrue(ReaderService.AddReader("Britney", "Spears")); Reader reader = ReaderService.GetReader("Britney", "Spears"); Assert.IsTrue(BookService.AddBook("Awesome Author", "Awesome Title", 2020, "Cute", 10)); Book book = BookService.GetBook("Awesome Title", "Awesome Author"); EventService.BorrowBookForReader(book, reader); EventService.ReturnBookByReader(book, reader); IEnumerable <Event> events = EventService.GetEventsForReaderByName("Britney", "Spears"); Assert.AreEqual(events.Count(), 2); //restore db Assert.IsTrue(ReaderService.DeleteReader(reader.reader_f_name, reader.reader_l_name)); Assert.IsNull(EventService.GetEventsForReaderByName("Britney", "Spears")); Assert.IsTrue(BookService.DeleteBook("Awesome Title")); }
public void AddExisistingReaderToDatabaseTest() { Assert.IsFalse(ReaderService.AddReader("Neave", "Oneal")); Assert.AreEqual(ReaderService.GetAllReadersNumber(), 5); }
//会员办证(添加读者) public int AddReader(Reader objReader) { return(objReaderService.AddReader(objReader)); }
static void Main(string[] args) { using (BookService service = new BookService()) { List <Book> books = service.GetAll(); // test if we get date from the DB Book book = books.FirstOrDefault(); // edit a book book.Quantity++; service.EditBook(book); // get book by ID Book book2 = service.GetBookByID(book.ID); // add new book Book newBook = new Book { Author = "Microsoft", Title = "Creating API", Description = "книга за програмиране", Genre = "programming", Quantity = 1, CreatedDate = DateTime.Now }; service.AddBook(newBook); // find book by author and delete if we have > 1 var booksByAuthor = service.GetByAuthor("Microsoft"); if (booksByAuthor.Count > 1) { int bookID = booksByAuthor.Last().ID; service.DeleteBook(bookID); } } //// another way to get all books - do not use this way, use BookService //LibraryContext context = new LibraryContext(); //var x = context.Books.ToList(); using (ReaderService readerService = new ReaderService()) { // add new reader Reader newReader = new Reader { FirstName = "reader", LastName = DateTime.Now.ToShortTimeString(), PhoneNumber = "08812345678", CreatedDate = DateTime.Now }; readerService.AddReader(newReader); int readerID = newReader.ID; // get reader by ID Reader reader2 = readerService.GetReaderByID(readerID); // edit reader reader2.FirstName = "reader " + readerID; readerService.EditReader(reader2); } using (BookService bookService = new BookService()) using (ReaderService readerService = new ReaderService()) { // get some valid IDs int bookID = bookService.GetByAuthor("Microsoft").First().ID; int readerID = readerService.GetAll().Last().ID; // borrow book readerService.BorrowBook(readerID, bookID); // return book Thread.Sleep(50); readerService.ReturnBook(readerID, bookID); } }
public void AddExisistingReaderToDatabaseTest() { Assert.IsFalse(ReaderService.AddReader("Neave", "Oneal")); }