public void CreateNote( Note note ) { if ( note == null ) throw new ArgumentNullException( "note" ); note.Employee = this.Session.Employee; BusinessRulesManager.Assert( "CreateNote", note ); StorageContext.Current.Insert( note ); }
private void buttonOk_Click( object sender, EventArgs e ) { Note note = new Note(); note.Date = DateTime.Now; note.Owner = this.entity; note.Text = this.textBoxText.Text; note.Title = this.textBoxTitle.Text; this.noteProcesses.Value.CreateNote( note ); this.DialogResult = DialogResult.OK; this.Close(); }
public void ReportLostBook( EntityRef<Rental> rentalRef ) { if ( rentalRef.IsNull ) throw new ArgumentNullException( "rentalRef" ); Rental rental = rentalRef.GetVanillaEntity(); Book book = rental.Book.GetVanillaEntity(); // Check business rules. BusinessRulesManager.Assert( "ReportLostBook", rental ); // Apply the penalty. CustomerAccountLine penalty = new CustomerAccountLine { Customer = rental.Customer, Employee = this.Session.Employee, Rental = rentalRef, Date = DateTime.Today, Amount = -book.LostPenalty, Description = string.Format( "Lost of the book [{0}; {1}]", book.Authors, book.Title ) }; this.customerProcesses.AddCustomerAccountLine( penalty ); // Create a note for the penalty. Note note = new Note { Owner = rental, Employee = this.Session.Employee, Date = DateTime.Now, Title = "Penalty Applied", Text = string.Format( "A penalty of {2} EUR was applied for the lost of the book [{0}; {1}]", book.Authors, book.Title, -penalty.Amount ) }; StorageContext.Current.Insert( note ); // Update the rental. rental.ReturnDate = DateTime.Now; rental.Closed = true; StorageContext.Current.Update( rental ); // Delete the book. book.Deleted = true; StorageContext.Current.Update( book ); }
public void ReturnBook( EntityRef<Rental> rentalRef ) { if ( rentalRef.IsNull ) throw new ArgumentNullException( "rentalRef" ); Rental rental = rentalRef.GetVanillaEntity(); // Check business rules. BusinessRulesManager.Assert( "ReturnBook", rental ); // Check if the book has been returned in time and apply penalty. if ( DateTime.Today > rental.ScheduledReturnDate ) { int delay = (int) Math.Ceiling( ( DateTime.Today - rental.ScheduledReturnDate ).TotalDays ); CustomerAccountLine penalty = new CustomerAccountLine { Customer = rental.Customer, Employee = this.Session.Employee, Rental = rentalRef, Date = DateTime.Today, Amount = -0.1M*delay, Description = string.Format( "Delay of {0} day(s) while returning the book [{1}; {2}]", delay, rental.Book.Entity.Authors, rental.Book.Entity.Title ) }; this.customerProcesses.AddCustomerAccountLine( penalty ); Note note = new Note { Owner = rental, Title = "Penalty Applied", Employee = this.Session.Employee, Date = DateTime.Now, Text = string.Format( "A penalty of {3} EUR was applied for a {0}-day(s) delay while returning the book [{1}; {2}]", delay, rental.Book.Entity.Authors, rental.Book.Entity.Title, -penalty.Amount ) }; StorageContext.Current.Insert( note ); } rental.ReturnDate = DateTime.Now; rental.Closed = true; StorageContext.Current.Update( rental ); }