My project has the following setup
Controller -> Service (for validation) -> Repository (for LINQ) -> dbml -> Database
Controller
''# <AcceptVerbs(HttpVerbs.Post)> - hiding this line so that code formatting looks proper in SO.
Function Edit(ByVal user As Domain.User, ByVal id As Integer) As ActionResult
If ModelState.IsValid Then
If Not String.IsNullOrEmpty(user.UserName) AndAlso _
Not String.IsNullOrEmpty(user.WebSite) AndAlso _
Not String.IsNullOrEmpty(user.Email) AndAlso _
Not String.IsNullOrEmpty(user.About) AndAlso _
Not user.Region Is Nothing AndAlso _
Not user.BirthDate Is Nothing AndAlso _
Not user.isProfileComplete = True Then
user.isProfileComplete = True
user.Reputation = user.Reputation + 10
UserService.UpdateUser(user)
Else
UserService.UpdateUser(user)
End If
UserService.SubmitChanges()
Return RedirectToAction("Details", "Users", New With {.id = id, .slug = user.UserName})
Else
Return View(user)
End If
End Function
Service
Public Sub UpdateUser(ByVal user As User) Implements IUserService.UpdateUser
_UserRepository.UpdateUser(user)
End Sub
Public Sub SubmitChanges() Implements IUserService.SubmitChanges
_UserRepository.SubmitChanges()
End Sub
Repository
Public Sub UpdateUser(ByVal user As User) Implements IUserRepository.UpdateUser
Dim _user = (From u In dc.Users
Where u.ID = user.ID
Select u).Single
_user = user
End Sub
Public Sub SubmitChanges() Implements IUserRepository.SubmitChanges
dc.SubmitChanges()
End Sub
The problem is that it's not getting updated. I must be doing something quite stupid here. Any advice will be greatly appreciated.