Chapter 11: Deploying Web Services with WCF

313

Return (From cust In ctx.Customers

Select cust).ToList()

End Function

Public Function InsertCustomer(ByVal cust As Customer) As Integer Implements ICustomerService.InsertCustomer

Dim ctx = New MyShopDataContext

ctx.Customers.InsertOnSubmit(cust)

ctx.SubmitChanges()

Return cust.CustomerID

End Function

Public Sub UpdateCustomer(ByVal cust As Customer) Implements ICustomerService.UpdateCustomer Dim ctx As New MyShopDataContext

Dim customer = (From cst In ctx.Customers

Where cst.CustomerID = cust.CustomerID Select cst).SingleOrDefault()

If Not (customer Is Nothing) Then

With customer

.Age = cust.Age

.Birthday = cust.Birthday

.Income = cust.Income

.Name = cust.Name End With

ctx.SubmitChanges()

End If

End Sub

Public Sub DeleteCustomer(ByVal custID As Integer)

Dim ctx As New MyShopDataContext

Dim customer = (From cst In ctx.Customers

Page 336
Image 336
Microsoft 9GD00001 manual 313