I have created an Interface called ILoginService and a Class implementing this service called LoginService. I am passing a stored Procedure through this service that returns a Scalar value.
The problem is that ILoginService object returns a null value giving Object reference not set to an instance of an object Error
Please help with this code is as follows:
LoginService Code
public partial class LoginService : ILoginService
{
TimesheetsManagementEntities TimesheetDatabase = new TimesheetsManagementEntities();
private readonly ILoginService _LoginService;
object UserAutheticationStatusObject;
int UserAutheticationStatusCode;
public LoginService(ILoginService LoginService) {
_LoginService = LoginService;
}
public int UserAuthetication(string EmailId, string LoginPassword)
{
using (TimesheetDatabase) {
TimesheetDatabase.Database.Connection.Open();
var command = TimesheetDatabase.Database.Connection.CreateCommand();
command.CommandText = "dbo.UserLoginAuthentication";
command.CommandType = System.Data.CommandType.StoredProcedure;
UserAutheticationStatusObject = (command.ExecuteScalar());
}
UserAutheticationStatusCode = (int)UserAutheticationStatusObject;
return UserAutheticationStatusCode;
}
}
Controller code
public class AccountsController : Controller
{
private readonly ILoginService _LoginService;
int UserAuthenticationStatus;
public AccountsController(ILoginService LoginService) {
_LoginService = LoginService;
}
public AccountsController() { }
public ActionResult Login()
{
LoginViewModel LoginModel = new LoginViewModel();
UserAuthenticationStatus = _LoginService.UserAuthetication(LoginModel.EmailId, LoginModel.LoginPassword);
return View(LoginModel);
}
}
ViewModel Code
public class LoginViewModel
{
public string EmailId { get; set; }
public string LoginPassword { get; set; }
}