How to: Add Business Logic to the Domain Service
To add business logic to data modification methods
Public Sub InsertCustomer(ByVal customer As Customer) If (customer.SalesPerson = String.Empty) Then customer.SalesPerson = RetrieveSalesPersonForCompany(customer.CompanyName) End If If ((customer.EntityState = EntityState.Detached) _ = False) Then Me.ObjectContext.ObjectStateManager.ChangeObjectState(customer, EntityState.Added) Else Me.ObjectContext.Customers.AddObject(customer) End If End Sub <Ignore()> _ Public Function RetrieveSalesPersonForCompany(ByVal companyname As String) As String Dim salesPersonToAssign As String = "unassigned" Dim customers As List(Of Customer) customers = GetCustomers().Where(Function(c) c.CompanyName = companyname).ToList() If (customers.Count > 0) Then salesPersonToAssign = customers.First().SalesPerson End If Return salesPersonToAssign End Functionpublic void InsertCustomer(Customer customer) { if (customer.SalesPerson == String.Empty) { customer.SalesPerson = RetrieveSalesPersonForCompany(customer.CompanyName); } if ((customer.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(customer, EntityState.Added); } else { this.ObjectContext.Customers.AddObject(customer); } } [Ignore] public string RetrieveSalesPersonForCompany(string companyname) { string salesPersonToAssign = "unassigned"; List<Customer> customers = GetCustomers().Where(c => c.CompanyName == companyname).ToList(); if (customers.Count > 0) { salesPersonToAssign = customers.First().SalesPerson; } return salesPersonToAssign; }
To add a named update method
To add an invoke operation
Last updated