Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 9: Creating Web Applications with ASP.NET MVC 267
Public Function InsertCustomer(
ByVal cust As Customer) As Integer
m_ctx.Customers.InsertOnSubmit(cust)
m_ctx.SubmitChanges()
Return cust.CustomerID
End Function
Public Sub UpdateCustomer(ByVal cust As Customer)
Dim currentCust =
(From currCust In m_ctx.Customers
Where currCust.CustomerID = cust.CustomerID
Select currCust).SingleOrDefault()
If Not currentCust Is Nothing Then
With currentCust
.Age = cust.Age
.Birthday = cust.Birthday
.Income = cust.Income
.Name = cust.Name
End With
m_ctx.SubmitChanges()
End If
End Sub
Public Function GetCustomer(ByVal custID As Integer) As Customer
Dim customer =
(From cust In m_ctx.Customers
Where cust.CustomerID = custID
Select cust).SingleOrDefault()
Return customer
End Function
Public Function GetCustomers() As List(Of Customer)
Dim customers =