public async Task <IActionResult> Edit(int id, [Bind("ResearchId,BookId")] ResearchBook researchBook)
        {
            if (id != researchBook.ResearchId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(researchBook);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ResearchBookExists(researchBook.ResearchId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"]     = new SelectList(_context.Book, "Id", "Name", researchBook.BookId);
            ViewData["ResearchId"] = new SelectList(_context.Research, "Id", "Name", researchBook.ResearchId);
            return(View(researchBook));
        }
        private void AddBorrower()
        {
            try
            {
                if (!(tb_BFName.Text == ""))
                {
                    using (var ctx = new RRSContext())
                    {
                        int tempId = Int32.Parse(dataGridView_Borrow.SelectedRows[0].Cells[0].Value.ToString());


                        var categoryid = (from cats in ctx.ResearchBooks
                                          where cats.ThesisTitleId.Equals(tempId)
                                          select cats.NumberOfCopies).SingleOrDefault();

                        var bookBorrowed = categoryid - 1;

                        var rb = new ResearchBook()
                        {
                            ThesisTitleId = tempId, NumberOfCopies = bookBorrowed
                        };
                        ctx.ResearchBooks.Attach(rb);
                        ctx.Entry(rb).Property(x => x.NumberOfCopies).IsModified = true;
                        ctx.SaveChanges();


                        var borrow = new Borrow
                        {
                            BFullName        = tb_BFName.Text,
                            BContactNumber   = tb_BContactNumber.Text,
                            BookBorrowedDate = DateTime.Now,
                            DateWillRetrun   = dateTimePicker_Return.Value.Date,
                            ThesisTitleId    = tempId,
                            NoOfBookBorrowed = 1,
                        };
                        ctx.Borrows.AddOrUpdate(borrow);
                        ctx.SaveChanges();

                        tb_BFName.Clear();
                        tb_BContactNumber.Clear();
                        dateTimePicker_Return.Value = DateTime.Now;

                        LoadBorrower();

                        ListofBorrowedBooks listofBorrowedBooks = new ListofBorrowedBooks();
                        listofBorrowedBooks.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("Add a borrower name");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async Task <IActionResult> Create([Bind("ResearchId,BookId")] ResearchBook researchBook)
        {
            if (ModelState.IsValid)
            {
                _context.Add(researchBook);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"]     = new SelectList(_context.Book, "Id", "Name", researchBook.BookId);
            ViewData["ResearchId"] = new SelectList(_context.Research, "Id", "Name", researchBook.ResearchId);
            return(View(researchBook));
        }