在ASP.NET MVC中,我有2个“登录”操作几乎可以完成相同的操作,但是它们使用不同的模型并返回不同的视图。如何确保我遵循DRY规则执行这些操作?
我尝试制作一个单独的函数来接收我需要的参数,但是由于模型不同,我无法做到这一点。
这是两个动作:
Public Function Login(model As accountViewModels.InternalLoginViewModel,location As String) As actionResult
...
If ... Then
...
Return View(model)
End If
If Not ModelState.IsValid Then
Return View(model)
End If
...
If authenticationResult.Success Then
...
ElseIf ... Then
Dim appUser As ApplicationUser = authService.GetapplicationUser(model.Emailusername)
...
ElseIf .. Then
Return RedirectToaction("OldAppnuserRegister",MVC_CONTROLLER_accOUNT,authenticationResult.OldUser.GetRouteValues(location))
ElseIf ... Then
Return RedirectToaction("Index",MVC_CONTROLLER_MANAGE,New With {.userKey = authService.GetapplicationUser(model.Emailusername).Key.ToString})
End If
...
Return View(model)
End Function
---------------
Public Function RepLogin(model As RepSessionViewModels.InternalLoginViewModel,location As String) As actionResult
...
If ... Then
...
Return View("~/Views/RepSession/SelectProvider.vbhtml",model)
End If
If Not ModelState.IsValid Then
Return View("~/Views/RepSession/SelectProvider.vbhtml",model)
End If
...
If authenticationResult.Success Then
...
ElseIf ... Then
Dim appUser As ApplicationUser = authService.GetapplicationUser(model.Email)
...
ElseIf ... Then
Return RedirectToaction("OldRepRegister",New With {.userKey = authService.GetapplicationUser(model.Email).Key.ToString})
End If
...
Return View("~/Views/RepSession/SelectProvider.vbhtml",model)
End Function
我将重复的代码替换为“ ...”以使其更具可读性。感谢所有帮助。谢谢。