public bool Return(Loan loan) { History loanHistory = new History { UserId = loan.UserId, BookISBN = loan.BookISBN, LeantDate = loan.LeantDate, ReturnDate = loan.ExpectedReturnDate }; Book returnedBook = this.context.Books.Select(x => x).Where(y => y.ISBN == loan.BookISBN).Take(1).FirstOrDefault(); try { if (returnedBook != null) { returnedBook.Copies += 1; } else { throw new ArgumentException("You tried to return a book that is no in the library!"); } this.context.Histories.InsertOnSubmit(loanHistory); this.context.Loans.DeleteOnSubmit(loan); loan.User.TakenBooks -= 1; this.context.SubmitChanges(); } catch (SqlException e) { Console.WriteLine(e.Message); return false; } catch (ArgumentException e) { Console.WriteLine(e.Message); return false; } return true; }
private void detach_Histories(History entity) { this.SendPropertyChanging(); entity.User = null; }
private void attach_Histories(History entity) { this.SendPropertyChanging(); entity.User = this; }
partial void DeleteHistory(History instance);
partial void UpdateHistory(History instance);
partial void InsertHistory(History instance);