本文整理汇总了C#中EntityRef.GetVanillaEntity方法的典型用法代码示例。如果您正苦于以下问题:C# EntityRef.GetVanillaEntity方法的具体用法?C# EntityRef.GetVanillaEntity怎么用?C# EntityRef.GetVanillaEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityRef
的用法示例。
在下文中一共展示了EntityRef.GetVanillaEntity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReportLostBook
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 );
}
示例2: DeleteCustomer
// [Transaction]
public void DeleteCustomer( EntityRef<Customer> customerRef )
{
if ( customerRef.IsNull )
throw new ArgumentNullException( "customerRef" );
// Get a safe version of the customer.
Customer customer = customerRef.GetVanillaEntity();
// Check business rules.
BusinessRulesManager.Assert( "DeleteCustomer", customer );
// Update the 'Deleted' flag.
customer.Deleted = true;
StorageContext.Current.Update( customer );
}
示例3: ReturnBook
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 );
}
示例4: GetCustomerInfo
public CustomerInfo GetCustomerInfo( EntityRef<Customer> customer, bool getAllRentals )
{
if ( customer.IsNull )
throw new ArgumentNullException( "customer" );
CustomerInfo customerInfo = new CustomerInfo {Customer = customer.GetVanillaEntity(), Rentals = new List<RentalInfo>()};
foreach ( Rental rental in StorageContext.Current.Find<Rental>( candidate => candidate.Customer == customer && (getAllRentals || !candidate.Closed) ) )
{
RentalInfo rentalInfo = new RentalInfo();
rentalInfo.Book = rental.Book.Entity;
rentalInfo.Rental = rental;
rentalInfo.Notes = new List<Note>( StorageContext.Current.Find<Note>( candidate => candidate.Owner == rental ) );
customerInfo.Rentals.Add( rentalInfo );
}
customerInfo.AccountLines = new List<CustomerAccountLine>( StorageContext.Current.Find<CustomerAccountLine>(
candidate => candidate.Customer == customer ) );
return customerInfo;
}