예제 #1
0
        public async Task <IActionResult> Register([FromBody] UserDTO userDTO)
        {
            var location = GetControllerActionNames();

            try
            {
                var username = userDTO.EmailAddress;
                var password = userDTO.Password;
                logger.LogInfo($"{location}:Register Attempt From User {username}");
                var user = new IdentityUser
                {
                    Email    = username,
                    UserName = username
                };
                var result = await userManeger.CreateAsync(user, password);

                if (!result.Succeeded)
                {
                    foreach (var error in result.Errors)
                    {
                        logger.LogError($"{location}:User Registration Failed {error.Code} - {error.Description}");
                    }
                    return(internalError(($"{location}:Register Attempt From User {username}  failed")));
                }
                return(Ok(new { result.Succeeded }));
            }
            catch (Exception e)
            {
                return(internalError($"{e.Message}-{e.InnerException}"));
            }
        }
예제 #2
0
        public async Task <IActionResult> GetBook(int id)
        {
            var location = GetControllerActionNames();

            try
            {
                _logger.LogInfo("Trying to get all of Flys Book store Authors");
                var book = await _bookRepository.FindByID(id);

                var response = _mapper.Map <BookDTO>(book);
                if (!string.IsNullOrEmpty(response.Image))
                {
                    var imgPath = GetImagePath(book.Image);
                    if (System.IO.File.Exists(imgPath))
                    {
                        byte[] imgBytes = System.IO.File.ReadAllBytes(imgPath);
                        response.File = Convert.ToBase64String(imgBytes);
                    }
                }



                _logger.LogInfo("Bingo got flys Book with no issues");
                return(Ok(response));
            }
            catch (Exception e)
            {
                _logger.LogIError($"{location} {e.Message } - {e.StackTrace }");
                return(StatusCode(500, "Opps The Fly Get Authors Call did not work as expected"));
            }
        }
        public async Task <IActionResult> Login([FromBody] UserDTO userDTO)

        {
            var location = GetControllerActionNames();

            try
            {
                var username = userDTO.EmailAddress;
                var password = userDTO.Password;
                _logger.LogInfo($"{location} : Login Attempt from user {username} ");
                var result = await _signInManager.PasswordSignInAsync(username, password, false, false);

                if (result.Succeeded)
                {
                    _logger.LogInfo($"{location} : {username} Had no issues logging in.");
                    var user = await _userManager.FindByNameAsync(username);

                    var tokenString = await GenerateJSONWebToken(user);

                    return(Ok(new { token = tokenString }));
                }

                return(Unauthorized(userDTO));
            }
            catch (Exception e)
            {
                _logger.LogIError($"{e.Message } - {e.StackTrace }");
                return(StatusCode(500, "Opps The Fly Users Have an issue."));
            }
        }
예제 #4
0
        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"));
            }
        }
예제 #5
0
        public async Task <IActionResult> GetBooks()
        {
            var location = GetControllerActionNames();

            try
            {
                _logger.LogInfo($"{location}: Attempet Call");
                var books = await _bookRepository.FindAll();

                var response = _map.Map <IList <BookDTO> >(books);
                _logger.LogInfo($"{location}: Attempet Call Succesful");
                return(Ok(response));
            }
            catch (Exception e)
            {
                return(internalError($"{location}:{e.Message}-{e.InnerException}"));
            }
        }
예제 #6
0
        public async Task <IActionResult> GetAuthors()
        {
            try
            {
                _logger.LogInfo("Attemped get all Authors");
                var authors = await _authorRepository.FindAll();

                if (authors == null)
                {
                    _logger.LogWarn("No authors Avalible");
                    return(NotFound());
                }
                var response = _map.Map <IList <AuthorDTO> >(authors);
                _logger.LogInfo("Succesfully Got All Authors");
                return(Ok(response));
            }
            catch (Exception e)
            {
                return(internalError($"{e.Message}-{e.InnerException}"));
            }
        }
예제 #7
0
 public string Get(int id)
 {
     _logger.LogInfo("Got Value");
     return("value");
 }
 public void Delete(int id)
 {
     _logger.LogInfo("Accessed Flys Home Controller and got a Warning");
 }
예제 #9
0
 public IEnumerable <string> Get()
 {
     _logger.LogInfo("AccesedHomeController");
     return(new string[] { "value1", "value2" });
 }