public async Task <IActionResult> Register([FromBody] UserDTO userDTO) { var location = GetControllerActionNames(); try { var username = userDTO.EmailAddress; var password = userDTO.Password; var user = new IdentityUser { Email = username, UserName = username }; var result = await _userManager.CreateAsync(user, password); if (!result.Succeeded) { _logger.LogIError($"{username} Failed Registration Attempt"); foreach (var error in result.Errors) { _logger.LogIError($"{location} : {error.Code} {error.Description}"); } return(InternalError($"{location} Failed Registration Attempt")); } return(Ok(new { result.Succeeded })); } catch (Exception e) { return(InternalError($"{location} Failed Registration Attempt")); } }
public async Task <IActionResult> GetAuthors() { try { _logger.LogInfo("Trying to get all of Flys Book store Authors"); var authors = await _authorRepository.FindAll(); var response = _mapper.Map <IList <AuthorDTO> >(authors); _logger.LogInfo("Bingo got flys BookStore Authors with no issues"); return(Ok(response)); } catch (Exception e) { _logger.LogIError($"{e.Message } - {e.StackTrace }"); return(StatusCode(500, "Opps The Fly Get Authors Call did not work as expected")); } }
public async Task <IActionResult> Delete(int id) { var location = GetControllerActionNames(); try { if (id < 1) { _logger.LogWarn($"Empty Request was submitted"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogWarn($"Bad Data Dude"); return(BadRequest(ModelState)); } var book = await _bookRepository.FindByID(id); if (book == null) { return(NotFound()); } //ToDo: add isExists logic //Todo: Refactor Errors and messages var isSuccess = await _bookRepository.Delete(book); if (!isSuccess) { // _logger.LogIError($"{location} {e.Message } - {e.StackTrace }"); _logger.LogWarn($"Bad Data Dude"); return(InternalError($"Did not Delete from Flys Book store ")); } return(NoContent()); } catch (Exception e) { _logger.LogIError($"{location} {e.Message } - {e.StackTrace }"); return(InternalError($"{e.Message } - {e.StackTrace }")); } }