/// <summary>
/// Checks in the item with the given ISBN & copy number.
/// </summary>
/// <param name="isbn">The ISBN of the item to be checked in.</param>
/// <param name="copyNo">The item's copy number.</param>
public void CheckIn(int isbn, short copyNo)
{
Require.IsGreaterThan<int>(isbn, 0, "isbn");
Require.IsGreaterThan<int>(( int ) copyNo, 0, "copyNo");
try
{
using ( LibraryDataContext dataContext = new LibraryDataContext() )
{
var CheckQuery = from CHQ in dataContext.loans
where CHQ.isbn == isbn && CHQ.copy_no == copyNo
select new
{
CHQ.isbn,
CHQ.copy_no,
CHQ.title_no,
CHQ.member_no,
CHQ.due_date,
CHQ.out_date,
};
var entity1 = CheckQuery.SingleOrDefault();
if ( entity1 == null )
{
throw new LibraryException(ErrorCode.ItemNotFound);
}
loanhist entity2 = new loanhist()
{
isbn = entity1.isbn,
copy = entity1.copy_no,
member_no = entity1.member_no,
due_date = new DateTime?(entity1.due_date),
in_date = new DateTime?(DateTime.Now),
out_date = entity1.out_date,
title_no = entity1.title_no
};
dataContext.loanhists.InsertOnSubmit(entity2);
entity1.copy.on_loan = 'N';
dataContext.loans.DeleteOnSubmit(entity1);
dataContext.SubmitChanges();
}
}
catch (SqlException ex)
{
throw new LibraryException(ErrorCode.CheckInFailed, ex.Message);
}
}