Example #1
0
        /// <summary>
        /// 保存修改信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            //数据验证


            //封装对象
            Readers objReader = new Readers()
            {
                ReaderId      = readerEndit.ReaderId,
                ReaderName    = txtReaderName.Text.Trim(),
                Gender        = this.rdoMale.Checked ? "男": "女",
                RoleId        = Convert.ToInt32(cboReaderRole.SelectedValue.ToString()),
                PostCode      = txtPostcode.Text.Trim(),
                PhoneNumber   = txtPhone.Text.Trim(),
                ReaderAddress = txtAddress.Text.Trim(),
                ReaderImage   = this.pbReaderPhoto.Image != null ? new Common.SerializeObjectToString().SerializeObject(this.pbReaderPhoto.Image) : "",
            };



            //提交修改后的数据
            try
            {
                readerService.EditReader(objReader);
                MessageBox.Show("提交成功", "提示信息");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }
        }
Example #2
0
        public IHttpActionResult Put(ReaderModel reader)
        {
            try
            {
                ReaderService readerService = new ReaderService();
                Reader        dbReader      = readerService.GetReaderByID(reader.ID);
                if (dbReader == null)
                {
                    return(NotFound());
                }

                reader.CopyValuesToEntity(dbReader);
                readerService.EditReader(dbReader);

                return(StatusCode(HttpStatusCode.NoContent)); // or use Ok()
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.GetBaseException().Message));
            }
        }
Example #3
0
        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);
                }
        }
 /// <summary>
 /// 修改读者信息
 /// </summary>
 /// <param name="objReader"></param>
 /// <returns></returns>
 public int EditReader(Reader objReader)
 {
     return(objReaderService.EditReader(objReader));
 }
Example #5
0
 /// <summary>
 /// 修改读者信息
 /// </summary>
 /// <param name="reader"></param>
 /// <returns></returns>
 public int EditReader(Reader reader)
 {
     return(readerService.EditReader(reader));
 }