private void returnBookButton_Click(object sender, EventArgs e) { var returnBookForm = new ReturnBookForm(); DialogResult dialogResult = returnBookForm.ShowDialog(this); if (dialogResult == DialogResult.Cancel) { return; } int readerId = returnBookForm.SelectedReader.Id; var bookCopyInDealRepository = new BookCopyInDealRepository(); BookCopyInDeal bookCopyInDeal; var p = returnBookForm.booksDataGridView.SelectedRows; for (int i = 0; i < p.Count; i++) { bookCopyInDeal = bookCopyInDealRepository.FindById((int)p[i].Cells[0].Value); bookCopyInDeal.ActualDateOfReturning = DateTime.UtcNow; bookCopyInDealRepository.Update(bookCopyInDeal); } SetDataGridView(); _db.SaveChanges(); }
private void SetDataGridView(int readerId) { var bookCopyInDealRepository = new BookCopyInDealRepository(); booksDataGridView.DataSource = bookCopyInDealRepository.GetReadingBookCopiesByReaderId(readerId) .OrderBy(bcd => bcd.Id) .Select(bcd => new { bcd.Id, bcd.BookCopyId, bcd.BookCopy.BookId, bcd.BookCopy.Book.Name, Authors = SetAuthor(bcd.BookCopy.Book.Id), bcd.DealId, ReaderId = bcd.Deal.ReaderId, ReaderName = $"{bcd.Deal.Reader.Name} {bcd.Deal.Reader.Surname}", bcd.RequiredDateOfReturning }).ToList(); }
private void addDealButton_Click(object sender, EventArgs e) { var addDealForm = new AddDealForm(); DialogResult dialogResult = addDealForm.ShowDialog(this); if (dialogResult == DialogResult.Cancel) { return; } int readerId = addDealForm.SelectedReader.Id; var dealRepository = new DealRepository(); var bookCopyInDealRepository = new BookCopyInDealRepository(); BookCopyInDeal bookCopyInDeal; var bookCopyRepository = new BookCopyRepository(); Deal deal = new Deal { LibrarianId = _librarianId, ReaderId = readerId, Date = DateTime.UtcNow }; dealRepository.Create(deal); var p = addDealForm.booksDataGridView.SelectedRows; for (int i = 0; i < p.Count; i++) { bookCopyInDeal = new BookCopyInDeal { DealId = deal.Id, BookCopyId = bookCopyRepository.GetAvailableBookCopiesByBookId((int)p[i].Cells[0].Value)[0].Id, RequiredDateOfReturning = DateTime.UtcNow.AddDays((int)addDealForm.daysNumericUpDown.Value) }; bookCopyInDealRepository.Create(bookCopyInDeal); } }
public void deleteButton_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } var readerRepository = new ReaderRepository(); var dealRepository = new DealRepository(); var bookCopyInDealRepository = new BookCopyInDealRepository(); List <Deal> deals = dealRepository.GetDealsByReaderId(id); List <BookCopyInDeal> bookCopyInDeals = bookCopyInDealRepository.GetBookCopiesInDealByReaderId(id); for (int i = 0; i < bookCopyInDeals.Count; i++) { bookCopyInDealRepository.Remove(bookCopyInDeals[i].Id); } for (int i = 0; i < deals.Count; i++) { dealRepository.Remove(deals[i].Id); } readerRepository.Remove(id); _db.SaveChanges(); SetDataGridView(); MessageBox.Show("Объект удален"); } }