public async Task <IActionResult> Create([Bind("IssuedBookId,BookId,CustomerId,DateFrom,DateTo,ReturnDate")] IssuedBook issuedBook) { if (ModelState.IsValid) { _context.Add(issuedBook); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } var query = (from x in _context.Books join y in _context.IssuedBooks on new { Key1 = x.BookId, Key2 = true } equals new { Key1 = y.BookId, Key2 = !y.ReturnDate.HasValue } into result from r in result.DefaultIfEmpty() select new { x.BookId, x.Name, r.IssuedBookId } ).ToList().Where(x => x.IssuedBookId == 0); ViewData["BookId"] = new SelectList(query, "BookId", "Name", issuedBook.BookId); ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "FullName", issuedBook.CustomerId); return(View(issuedBook)); }
bool Extend(IssuedBook book, int days) { book.ReturnDate = book.ReturnDate.AddDays(days); book.ReturnDateExtended = true; _mgr.Create <IssuedBook>().Update(book); return(_mgr.Save() == 1 ? true : false); }
/// <summary> /// Adds a book into the issued book table /// </summary> /// <param name="book"></param> /// <returns></returns> public static int IssueBook(IssuedBook book) { using (con = new SqlConnection(conString)) { //Adds a book to the issued books table// con.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO IssuedBooks (StudentId, BookId, StudentName, title, Author, DateIssued, DueDate, Overdue, Returned) VALUES(@sId, @bId, @sName, @title, @author, @date, @due, @over, @return)", con); cmd.Parameters.AddWithValue("@sId", book.StudentId); cmd.Parameters.AddWithValue("@bId", book.BookId); cmd.Parameters.AddWithValue("@sName", book.StudentName); cmd.Parameters.AddWithValue("@title", book.Title); cmd.Parameters.AddWithValue("@author", book.Author); cmd.Parameters.AddWithValue("@date", book.DateIssued); cmd.Parameters.AddWithValue("@due", book.DueDate); cmd.Parameters.AddWithValue("@over", book.Overdue); cmd.Parameters.AddWithValue("@return", book.Returned); cmd.ExecuteNonQuery(); //Updates the available value in the books table// cmd.CommandText = "UPDATE Books SET Available=@ava, DueDate=@due Where BookId=@id"; cmd.Parameters.AddWithValue("ava", book.Available); cmd.Parameters.AddWithValue("id", CurrentId); return(cmd.ExecuteNonQuery()); } }
public AddEditIssuedBookForm(IssuedBook issuedBook, Book book, Reader reader, IssuedBooksRepository issuedBooksRepository) { InitializeComponent(); this.issuedBooksRepository = issuedBooksRepository; if (issuedBook == null) { this.Text = "Выдача книги"; state = AddEditFormState.Add; this.book = book; this.reader = reader; issuedBook = new IssuedBook { IdBook = book.Id, IdReader = reader.Id, DateIssue = DateTime.Now.Date, DateReturn = DateTime.Now.Date }; this.issuedBook = issuedBook; } else { this.Text = String.Format("Изменение выдачи (ID = {0})", issuedBook.Id); buttonOK.Text = "ОК"; state = AddEditFormState.Edit; dateTimeIssuePicker.Enabled = true; this.book = book; this.reader = reader; this.issuedBook = issuedBook; } BindDataToControls(); }
/// <summary> /// Issues the book to a specific student. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnIssue_Click(object sender, EventArgs e) { int available = int.Parse(dgvIssueBook.CurrentRow.Cells["Available"].Value.ToString()); string title = dgvIssueBook.CurrentRow.Cells["Title"].Value.ToString(); string student = cmbStudentName.SelectedItem.ToString(); BookHelper.CurrentId = int.Parse(dgvIssueBook.CurrentRow.Cells["BookId"].Value.ToString()); if (available > 0) { available--; IssuedBook book = new IssuedBook(null, int.Parse(cmbId.SelectedItem.ToString()), int.Parse(dgvIssueBook.CurrentRow.Cells["BookId"].Value.ToString()), student, title, dgvIssueBook.CurrentRow.Cells["Author"].Value.ToString(), DateTime.Today.ToString("MM/dd/yyyy"), dtpDueDate.Value.ToString("MM/dd/yyyy"), int.Parse(dgvIssueBook.CurrentRow.Cells["Copies"].Value.ToString()), available, "NO", 0); if (BookHelper.IssueBook(book) > 0) { DialogResult result = MessageBox.Show("A copy of " + title + " was issued to student: " + student, "Book Issued", MessageBoxButtons.OK, MessageBoxIcon.Information); if (result == DialogResult.OK) { BookHelper.LoadActive(dgvIssueBook); cmbId.SelectedIndex = -1; cmbStudentName.SelectedIndex = -1; dtpDueDate.Value = DateTime.Today.AddDays(10); } } } }
public static BookStatus ListIssuedBooksWithStatus(this IssuedBook issuedBookObject) { var difference = issuedBookObject.ProjectedReturnDate - DateTime.Now; BookStatus status = BookStatus.defaultStatus; if (difference.TotalDays <= 0) { status = BookStatus.notreturnedlatewarning; } else if (difference.TotalDays <= 2 && difference.TotalDays > 0) { status = BookStatus.notreturnedwarning; } else if (difference.TotalDays > 2) { status = BookStatus.notreturned; } if (issuedBookObject.ActualReturnDate != null) { status = BookStatus.returned; } return(status); }
public async Task <IActionResult> Edit(int id, [Bind("IssuedBookId,BookId,CustomerId,DateFrom,DateTo,ReturnDate")] IssuedBook issuedBook) { if (id != issuedBook.IssuedBookId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(issuedBook); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!IssuedBookExists(issuedBook.IssuedBookId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BookId"] = new SelectList(_context.Books, "BookId", "Name", issuedBook.BookId); ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "FullName", issuedBook.CustomerId); return(View(issuedBook)); }
public ActionResult DeleteConfirmed(int id) { IssuedBook issuedBook = db.IssuedBooks.Find(id); db.IssuedBooks.Remove(issuedBook); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "IssuedBookID,FKBookID,FKStudentID,createDate,isActive,Status")] IssuedBook issuedBook) { if (ModelState.IsValid) { db.Entry(issuedBook).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FKBookID = new SelectList(db.Books, "BookID", "BookName", issuedBook.FKBookID); ViewBag.FKStudentID = new SelectList(db.Students, "Student_ID", "StudentName", issuedBook.FKStudentID); return(View(issuedBook)); }
/* public List<User> GetAllUser(int pagenumber, int rowcount) * { * List<User> userList = null; * * try * { * SqlCommand sqlCommand = new SqlCommand("stp_FetchAllUsers", connection); * sqlCommand.CommandType = CommandType.StoredProcedure; * sqlCommand.Parameters.AddWithValue("@Page", pagenumber); * sqlCommand.Parameters.AddWithValue("@RowCountPerPage", rowcount); * connection.Open(); * * SqlDataReader reader = sqlCommand.ExecuteReader(); * if(reader.HasRows) * { * userList = new List<User>(); * } * while (reader.Read()) * { * userList.Add(new User() * { * Id = (string)reader["Id"], * Username = (string)reader["email_id"], * FirstName = (string)reader["firstname"], * LastName = (string)reader["lastname"], * Created = Convert.ToDateTime(reader["created"]), * Modified = Convert.ToDateTime(reader["modified"]) * }); * * } * return userList; * } * finally * { * if (connection != null) * { * connection.Close(); * } * } * }*/ public List <IssuedBook> UserHistory(string Userid) { List <IssuedBook> books = null; try { SqlCommand cmd = new SqlCommand("stp_UserIssuedBookHistory", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Userid", Userid); connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { books = new List <IssuedBook>(); } while (reader.Read()) { IssuedBook issuedBook = new IssuedBook(); //if(reader["actual_return_date"] != DBNull.Value) //{ // issuedBook.ActualReturnDate = Convert.ToDateTime(reader["actual_return_date"]); //} books.Add(new IssuedBook() { BookId = (string)reader["id"], BookCopyId = (string)reader["book_copy_id"], Title = (string)reader["title"], Author = (string)reader["author"], Edition = Convert.ToInt32(reader["book_edition"]), IssueDate = Convert.ToDateTime(reader["issue_date"]), ProjectedReturnDate = Convert.ToDateTime(reader["projected_return_date"]), ActualReturnDate = reader["actual_return_date"] == DBNull.Value ? (DateTime?)null : Convert.ToDateTime(reader["actual_return_date"]) }); } ; } finally { if (connection != null) { connection.Close(); } } return(books); }
bool Issue(Student student, Book book) { var issuedBook = new IssuedBook() { BookId = book.BookId, StudentId = student.StudentId, IssueDate = DateTime.Now, ReturnDate = DateTime.Now.AddDays(Day2Return) }; _mgr.Create <IssuedBook>().Add(issuedBook); return(_mgr.Save() == 1 ? true : false); }
// GET: IssuedBooks/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IssuedBook issuedBook = db.IssuedBooks.Find(id); if (issuedBook == null) { return(HttpNotFound()); } return(View(issuedBook)); }
public void Test_Method_IssuedBookConstructor() { Book k = new Book(); k.Title = "Sto godina samoce"; k.ISBN = "ISBN 1-12345-123-1"; k.Publisher = "Sarajevo publishing"; Member Haris = new Member("Haris", "Hasic", "2222222222222"); IssuedBook IssBook = new IssuedBook(Haris, k, Convert.ToDateTime("21.12.1912")); // Pogrešan unos datuma vraćanja (_returnBy) // očekivana pojava ArgumentException-a }
// GET: IssuedBooks/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IssuedBook issuedBook = db.IssuedBooks.Find(id); if (issuedBook == null) { return(HttpNotFound()); } ViewBag.FKBookID = new SelectList(db.Books, "BookID", "BookName", issuedBook.FKBookID); ViewBag.FKStudentID = new SelectList(db.Students, "Student_ID", "StudentName", issuedBook.FKStudentID); return(View(issuedBook)); }
public bool ExtendReturndate(IssuedBook book, int days) { if (book == null || days == 0) { throw new Exception("book not found/days to extendis 0"); } bool extended = false; try { extended = Extend(book, days); } catch (Exception) { //shout/catch/throw/log } return(extended); }
public async Task <IActionResult> MemberIssueBook(MemberIssueBookModel model) { var member = await _context.Members.FindAsync(model.MemberId); var book = await _context.Books.FindAsync(model.BookId); var issuedBook = new IssuedBook { Book = book, Member = member, IssuedDate = DateTime.UtcNow, ReturnDate = model.DueDate }; // adds to the db _context.IssuedBook.Add(issuedBook); // if a book is taken reduce it by one (stock) book.Quantity--; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public void extend_return_date_of_book_extends_the_return_date_of_the_book() { //given int randomIssuedBookId = rnd.Next(1, TestData.IssuedBooks.Count); int InputBookId = TestData.IssuedBooks.Where(i => i.IssuedBookId == randomIssuedBookId).First().BookId; IssuedBook InputBook = TestData.IssuedBooks.Where(b => b.BookId == InputBookId).First(); moqTxnMgr.Setup(m => m.Create <IssuedBook>().Update(It.IsAny <IssuedBook>())).Verifiable(); moqTxnMgr.Setup(m => m.Save()).Returns(1); var sut = new BookAllocationService(moqTxnMgr.Object); //when var result = sut.ExtendReturndate(InputBook, 5); //then Assert.IsInstanceOfType(result, typeof(bool)); Assert.IsTrue(result); moqTxnMgr.Verify(v => v.Create <IssuedBook>().Update(It.IsAny <IssuedBook>()), Times.Once); moqTxnMgr.Verify(v => v.Save(), Times.Once); }