Example #1
0
        public async Task <IActionResult> Login([FromBody] UserDTO userDTO)
        {
            try
            {
                _logger.LogInfo($"Login Attempt from User {userDTO.UserName}");
                var result = await _signInManager.PasswordSignInAsync(userDTO.UserName, userDTO.Password, false, false);

                if (result.Succeeded)
                {
                    _logger.LogInfo($"User {userDTO.UserName} Authenticated");
                    var user = await _userManager.FindByNameAsync(userDTO.UserName);

                    var token = await GenerateJWT(user);

                    return(Ok(new { token = token }));
                }
                else
                {
                    _logger.LogInfo($"User {userDTO.UserName} Not Authorized");
                    return(Unauthorized(userDTO.UserName));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(StatusCode(500, "Something went wrong"));
            }
        }
Example #2
0
 public DescriptiveResponse <bool> AddEmployee(Employee employee)
 {
     try
     {
         //JobRole role = _jobRoles.GetFirstOrDefult(employee.role.Id);
         //employee.role = role;
         var result = _employeeRepo.Attach(employee);
         var saved  = _unitOfWork.Commit();
         return(new DescriptiveResponse <bool>().success(true));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
         return(new DescriptiveResponse <bool>().Error(ex.Message));
     }
 }
 public void Post([FromBody] string value)
 {
     _logger.LogError("Accessed Home Post - Error");
 }
Example #4
0
 public void Post([FromBody] string value)
 {
     _logger.LogError("this is an error");
 }
 private ObjectResult InternalError(string message)
 {
     _logger.LogError(message);
     return(StatusCode(500, "Something went wrong. Please contact the administrator"));
 }