I am using web api and creating a login functionality.(n tier architecture). I am getting a null response in Login Controller.
First I want to confirm that is my code logic is correct and if it is correct then why i am getting response null in
HttpResponseMessage response = client.GetAsync("api/Login/Login").Result;
My Project UI Login Controller Code LoginCOntroller.cs
[HttpPost]
public ActionResult Login(LoginViewModel loginViewModel)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:63465/");
HttpResponseMessage response = client.GetAsync("api/Login/Login").Result;
if (response.IsSuccessStatusCode)
{
return RedirectToActionPermanent("Index", "Project");
}
return View(loginViewModel);
}
My Api Login Controller Code LoginController.cs
public HttpResponseMessage Login(LoginViewModel loginViewModel)
{
if (ModelState.IsValid)
{
UserEntity userEntity = new UserEntity();
userEntity.Email = loginViewModel.UserName;
userEntity.Password = loginViewModel.Password;
var login = new LoginManager().LoginAuthentication(userEntity);
if (login != null)
{
return Request.CreateResponse(login);
}
}
return Request.CreateResponse(true);
}
My Login manager Class LoginManager.cs
public class LoginManager
{
public UserEntity LoginAuthentication(UserEntity userDetails)
{
var userDetail = new LoginDa().LoginAuthentication(userDetails);
return userDetail;
}
}
My Data access layer LoginDa.cs
public class LoginDa
{
public UserEntity LoginAuthentication(UserEntity login)
{
using (var context = new ArcomDbContext())
{
var loginDetail = context.userInformation.FirstOrDefault(p => p.Email == login.Email && p.Password == login.Password);
return loginDetail;
}
}
}