public async Task<IHttpActionResult> PutBook(int id, Book book) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != book.Id) { return BadRequest(); } db.Entry(book).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public string Update <Book>(int id, Library.Models.Book book) { try { Library.Models.Book newBook = context.Lib.Where(s => s.Id == id).FirstOrDefault(); if (newBook == null) { return("Такой книги нет"); } using (var dbCtx = new LibraryContext()) { newBook.Number_copies = book.Number_copies; newBook.Short_description = book.Short_description; newBook.Book_title = book.Book_title; dbCtx.Entry(newBook).State = System.Data.Entity.EntityState.Modified; dbCtx.SaveChanges(); } context = new LibraryContext(); return("Данные изменены"); } catch (Exception ex) { throw ex; } }
private void DisplayBookPrice() { int Id = _context.Books.FirstOrDefault(b => b.Name == CmbCNOBook.Text).Id; SelectedBook = _context.Books.Find(Id); TxtCNOPrice.Text = SelectedBook.Price.ToString(); }
public Loan(string timeOfLoan, string dueDate, Book _book, Member _member) { this.LoanId = generateNewId(); this.TimeOfLoan = timeOfLoan; this.DueDate = dueDate; this.book = _book; this.member = _member; this.TimeOfRetrun = ""; }
// GET: Book/Details/5 public ActionResult Details(int id) { var model = _context.Books.FirstOrDefault(item => item.ID == id); if (model == null) { model = new Library.Models.Book(); } return(View(model)); }
/// <summary> /// Add new book copy /// </summary> /// <param name="book"></param> public void Add(Book book) { BookCopy bookCopy = new BookCopy() { Book = book }; _bookCopyRepository.Add(bookCopy); OnUpdated(new EventArgs()); }
public async Task<ApiResult> ReturnBook(int loanId) { if (!ModelState.IsValid) { return new ApiResult(ModelState); } var book = new Book(); bool saved = await _loanService.ReturnBook(loanId); return new ApiResult(); }
public ActionResult Edit(Book book) { if (ModelState.IsValid) { BookDAO.Update(book); return RedirectToAction("GenreBooks", "EditGenres", new { genreID = book.GenreID }); } else { return Edit(book.Id); } }
public async Task<IHttpActionResult> PostBook(Book book) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Book.Add(book); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = book.Id }, book); }
// POST api/Books public HttpResponseMessage PostBook(Book book) { if (!ModelState.IsValid) { var errorResponse = Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.GetModelStateErrors()); return errorResponse; } db.Books.Add(book); db.SaveChanges(); return Request.CreateErrorResponse(HttpStatusCode.OK, "Book added successfully."); }
public string Insert <Book>(Library.Models.Book book) { try { context.Lib.Add(book); context.SaveChanges(); return("Запись была добавлена"); } catch (Exception ex) { throw ex; } }
public Boolean addNewBook(Book book) { try { context.books.Add(book); context.SaveChanges(); return true; } catch { return false; } }
public string Delete <Book>(Library.Models.Book book) { try { var delBook = context.Lib.Find(book.Id); context.Lib.Remove(delBook); context.SaveChanges(); return("Запись удалена"); } catch (Exception ex) { throw ex; } }
public ActionResult Create(Book book) { if (ModelState.IsValid) { BookDAO.Create(book); return RedirectToAction("GenreBooks", "EditGenres", new { genreID = book.GenreID }); } else { ViewBag.AuthorID = new SelectList(AuthorDAO.FindAll(), "Id", "LastName"); ViewBag.GenreID = new SelectList(GenreDAO.FindAll(), "Id", "Title", book.GenreID); return View(book); } }
public async Task<ApiResult> CreateBook([FromBody]BookChangeDto bookDto) { if (!ModelState.IsValid) { return new ApiResult(ModelState); } var book = new Book(); await _bookService.CreateBook(Mapper.Map(bookDto, book)); return new ApiResult { Data = Mapper.Map(book, new BookDetailedResultDto()) }; }
private void DgvBook_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { BtnAdd.Visible = false; BtnDelete.Visible = true; BtnUpdate.Visible = true; ResetForm(); foreach (var item in _context.Books.ToList()) { int Id = Convert.ToInt32(DgvBook.Rows[e.RowIndex].Cells[0].Value.ToString()); SelectedBook = _context.Books.Find(Id); TxtName.Text = SelectedBook.Name; TxtPrice.Text = SelectedBook.Price.ToString(); NumCount.Value = SelectedBook.Count; } }
public AddBookViewModel() { AddBook = new RelayCommand(() => { Book newBook =new Book(ISBN, Title, Author, false); ObservableCollection<Book> LstBooks = ((ViewModelLocator)Application.Current.Resources["Locator"]).ListOfBooksViewModel.LstBooks ; LstBooks.Add(newBook); ((ViewModelLocator)Application.Current.Resources["Locator"]).DetailsBookViewModel.CurrentBook = newBook; var rootFrame = (App.Current as App).RootFrame; rootFrame.Navigate(new Uri("/DetailsBook.xaml", UriKind.Relative)); ISBN = ""; Title = ""; Author = ""; }); ViewLoadedCommand = new RelayCommand(() => { }); }
public void ParseCsv() { var path = Application.StartupPath + "/../../Files/library.csv"; var lines = File.ReadAllLines(path, Encoding.GetEncoding("iso-8859-1")); foreach (string line in lines) { var items = line.Split(new string[] { ";" }, StringSplitOptions.None); string key = items[2] + items[3]; if (!authorList.ContainsKey(key)) { Author author; author = new Author { Name = items[2] + " " + items[3]}; authorList.Add(items[2] + items[3], author); } Book bookToAdd = new Book { Title = items[1], Author = authorList.Where(a => a.Key == items[2] + items[3]).First().Value, Isbn = items[0], Description = items[4], Copies = new List<BookCopy>()}; bookList.Add(bookToAdd); } }
/// <summary> /// Add new book /// </summary> /// <param name="title"></param> /// <param name="description"></param> /// <param name="isbn"></param> /// <param name="author"></param> /// <param name="noOfCopies"></param> public void Add(string title, string description, string isbn, Author author, int noOfCopies) { if (ContainsTitle(title)) { throw new ValidationException("The title you are trying to add already exists"); } else if (ContainsISBN(isbn)) { throw new ValidationException("The ISBN you are trying to add already exists"); } Book book = new Book() { Title = title, Description = description, ISBN = isbn, Author = author }; // Add book copies to the new book List<BookCopy> bookCopies = new List<BookCopy>(); for (int i = 0; i < noOfCopies; i++) { bookCopies.Add(new BookCopy() {Book = book}); } book.BookCopies = bookCopies; ValidationResult error = ObjectValidator.Validate(book); if (error != null) { throw new ValidationException(error.ErrorMessage); } else { _bookRepository.Add(book); OnUpdated(new EventArgs()); } }
// PUT api/Books/5 public HttpResponseMessage PutBook(int id, Book book) { if (!ModelState.IsValid) { var errorResponse = Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.GetModelStateErrors()); return errorResponse; } if (id != book.Id) { var errorResponse = Request.CreateErrorResponse( HttpStatusCode.BadRequest, string.Format("Id mismatch error: id={0}, book.Id={1}", id, book.Id)); return errorResponse; } db.Entry(book).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { var errorResponse = Request.CreateErrorResponse( HttpStatusCode.NotFound, string.Format("No book with id={0} was found.", id)); return errorResponse; } else { throw; } } return Request.CreateErrorResponse(HttpStatusCode.OK, "Book updated successfully."); }
private void BtnAdd_Click(object sender, EventArgs e) { if (!Validation()) { return; } Library.Models.Book book = new Library.Models.Book(); book.Name = TxtName.Text; book.Price = Convert.ToDecimal(TxtPrice.Text); book.Count = Convert.ToInt32(NumCount.Text); #region Verifying that duplicate book name is not entered in the system List <Library.Models.Book> bk = _context.Books.OrderByDescending(b => b.Id).Where(b => b.Name.Contains(TxtName.Text)).ToList(); foreach (var item in bk) { if (item.Name == book.Name) { LblName.ForeColor = Color.Red; MessageBox.Show("Entered book name already exists in the library.", "Attention"); ResetForm(); return; } } #endregion _context.Books.Add(book); _context.SaveChanges(); FillBookList(); ResetForm(); MessageBox.Show("New Book is successfully added to the list.", "UPDATE"); }
private void btnSave_Click(object sender, EventArgs e) { string name = txtName.Text; decimal price = Convert.ToDecimal(txtPrice.Text); int count = Convert.ToInt32(txtCount.Text); int selected = cmbCategories.SelectedIndex; int catID = categories[selected].Id; using (LibraryDB db = new LibraryDB()) { Models.Book book = new Models.Book() { Name = name, Price = price, Count = count, CategoryID = catID }; db.Books.Add(book); db.SaveChanges(); foreach (int item in lbAuthors.SelectedIndices) { AuthorsBook ab = new AuthorsBook { BookID = book.Id, AuthorID = authors[item].Id }; db.AuthorsBooks.Add(ab); db.SaveChanges(); } } FillBooks(); }
private void buttonValidate_Click(object sender, RoutedEventArgs e) { if (!isEmpty()) { string studentID = textStudentID.Text; string bookID = textBookID.Text; //string[] info = Queries.QueryBorrow.getInfo(bookID, studentID); Models.Book book = Queries.QueryBooks.book.Find(x => x.BookID + "" == bookID); Models.Student student = Queries.QueryStudent.student.Find(x => x.StudentId + "" == studentID); textTitle.Text = book.Title; comboAuthor.Text = book.Author; textYear.Text = book.Year + ""; textQuantity.Text = book.Quantity + ""; textComments.Text = book.Comments; textStudentName.Text = student.FirstName + " " + student.LastName; textStudentLevel.Text = student.Grade + ""; textStudentSection.Text = student.Section; } else { MessageBox.Show("Please fill out all fields.", "Empty Data", MessageBoxButton.OK); } }
public async Task Update(Book b) { await _libraryContext.SaveChangesAsync(); }
public async Task<int> CreateBook(Book b) { _libraryContext.Books.Add(b); return await _libraryContext.SaveChangesAsync(); }
public BookModel() { _book = new Book(); }
public BookCopy(Book _book) { this.BookCopyId = generateNewId(); this.book = _book; }
public void Add(Book item) { }
public void Remove(Book item) { }
public BookCopy(Book _book) { this.book = _book; this.IsLoaned = false; this.IsReturned = false; }
public bool updateBook(Book book) { try { context.Entry(book).State = EntityState.Modified; context.SaveChanges(); } catch { return false; } return true; }
partial void InsertBook(Book instance);
partial void UpdateBook(Book instance);
partial void DeleteBook(Book instance);
public ActionResult Create(BookViewModel model) { Library.Models.Book existingBook = null; try { existingBook = _context.Books.FirstOrDefault(item => item.ISBN.Equals(model.Book.ISBN)); if (existingBook != null) { ModelState.AddModelError("ISBN", "A book by this ISBN already exists."); } } catch { } if (ModelState.IsValid) { if (model.Book.AuthorID == 0) { var Author = new Models.Author(); Author.FirstName = (string.IsNullOrEmpty(model.Author.FirstName)) ? "Unknown" : model.Author.FirstName; Author.LastName = (string.IsNullOrEmpty(model.Author.LastName)) ? "Unknown" : model.Author.LastName; Author.CreatedBy = User.Identity.Name; Author.CreatedOn = DateTime.Now; Author.LastModifiedBy = User.Identity.Name; Author.LastModifiedOn = DateTime.Now; Author.IsDeleted = false; // set AuthorID to new Author Author = _context.Authors.Add(Author); _context.SaveChanges(); model.Book.AuthorID = Author.ID; model.Author = Author; } try { // TODO: Add insert logic here // update virtual properties model.Book.CreatedBy = User.Identity.Name; model.Book.CreatedOn = DateTime.Now; model.Book.LastModifiedBy = User.Identity.Name; model.Book.LastModifiedOn = DateTime.Now; model.Book.IsDeleted = false; // add the new author to the database. _context.Books.Add(model.Book); // save the changes. _context.SaveChanges(); return(RedirectToAction("Index")); } catch { model.Authors = _context.Authors.ToList(); return(View(model)); } } model.Authors = _context.Authors.ToList(); // add option to authors list model.Authors.Insert(0, new Models.Author { FirstName = "Select", LastName = "Author" }); return(View(model)); }
public void AddBook(Book book) { _book = book; _books.Add(book); WriteToXml(); }
public void Edit(Book item) { }
public bool returnBook(Book book) { book.copies++; return (new BooksController()).updateBook(book); }
public void AddItemCheckout(Book item) { AvailableItems.Add(item); }
private void SendMail(UserName user, Book book) { MailAddress from = new MailAddress("*****@*****.**", "Library"); MailAddress to = new MailAddress(user.Email); MailMessage msg = new MailMessage(from, to); msg.Subject = "You have a new book"; msg.Body = string.Format("{0}, you are successfully taken a book called \"{1}\"", user.Name, book.Name); SmtpClient smtp = new SmtpClient(); smtp.Send(msg); }