public override bool Equals(System.Object otherCheckout) { if (!(otherCheckout is Checkout)) { return(false); } else { Checkout newCheckout = (Checkout)otherCheckout; bool idEquality = (this.GetId() == newCheckout.GetId()); bool dueDateEquality = (this.GetDueDate() == newCheckout.GetDueDate()); bool returnDateEquality = (this.GetReturnDate() == newCheckout.GetReturnDate()); bool patronsIdEquality = (this.GetPatronsId() == newCheckout.GetPatronsId()); bool copiesIdEquality = (this.GetCopiesId() == newCheckout.GetCopiesId()); return(idEquality && dueDateEquality && returnDateEquality && patronsIdEquality && copiesIdEquality); } }
public void Test_UpdateReturnDate_UpdatesReturnDateinDB() { //Arrange DateTime dueDate = new DateTime(2017, 3, 15); DateTime returnDate = new DateTime(2017, 3, 7); Checkout testCheckout = new Checkout(dueDate, 1, 1); testCheckout.Save(); DateTime newReturnDate = new DateTime(2017, 4, 7); //Act testCheckout.UpdateReturnDate(newReturnDate); //Assert DateTime actualResult = testCheckout.GetReturnDate(); DateTime expectedResult = newReturnDate; Assert.Equal(expectedResult, actualResult); }
//Returns a book to the library and sets the return date in Checkout object public void ReturnBook(int patronId) { SqlConnection conn = DB.Connection(); conn.Open(); DateTime today = DateTime.Today; SqlCommand cmd = new SqlCommand("UPDATE checkouts SET date_returned = @ReturnDate WHERE patrons_id = @PatronId AND copies_id IN (SELECT id FROM copies WHERE books_id = @BookId);", conn); cmd.Parameters.Add(new SqlParameter("@PatronId", patronId)); cmd.Parameters.Add(new SqlParameter("@BookId", this.GetId())); cmd.Parameters.Add(new SqlParameter("@ReturnDate", today)); SqlDataReader rdr = cmd.ExecuteReader(); int myCheckoutId = 0; while (rdr.Read()) { myCheckoutId = rdr.GetInt32(0); Checkout myCheckout = Checkout.Find(myCheckoutId); Console.WriteLine("MYCHECKOUT: " + myCheckout.GetReturnDate()); myCheckout.UpdateReturnDate(today); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } }