public IHttpActionResult Login(UserNamePasswordModel loginModel) { EmployeeModel employee = employeesRepository.GetByUserNameAndPassword(loginModel.UserName, loginModel.Password); IHttpActionResult httpActionResult = BadRequest("The user name or password is incorrect"); if (employee != null) { httpActionResult = Ok(employee); } return(httpActionResult); }
/// <summary> /// Tries to login the employee to the server /// with the specified user name and password retrived /// via binding. /// </summary> public void Login() { UserNamePasswordModel userNamePassword = new UserNamePasswordModel(UserName, Password); var jsonObject = JsonConvert.SerializeObject(userNamePassword); var stringContent = new StringContent(jsonObject, UnicodeEncoding.UTF8, "application/json"); HttpClient httpClient = new HttpClient(); HttpResponseMessage res = httpClient.PostAsync(loginUrl, stringContent).Result; if (res.IsSuccessStatusCode) { EmployeeModel employee = res.Content.ReadAsAsync <EmployeeModel>().Result; OpenHomeViewAsync(employee); } else { Message = "User name or password are incorrect"; } }