public async Task <RequestResponseModel <AuthenticationViewModel> > AuthenticateUserAsync(LoginWriteModel loginModel) { var errors = await _userValidator.CheckLoginCredentials(loginModel); if (errors.Any()) { return(new RequestResponseModel <AuthenticationViewModel>(StatusCodes.Status400BadRequest, errors, null)); } var user = await _userRepository.GetUserByUsernameAsync(loginModel.Username); var authenticationToken = _tokenGenerator.GenerateToken(user.Username, user.Role); return(new RequestResponseModel <AuthenticationViewModel>(StatusCodes.Status200OK, Enumerable.Empty <ErrorViewModel>(), new AuthenticationViewModel { AuthenticationToken = authenticationToken, Username = loginModel.Username, UserId = user.UserId })); }