Пример #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"));
            }
        }
Пример #2
0
        public async Task <IActionResult> GetBooks()
        {
            try
            {
                _logger.LogInfo($"{GetCallLocation()}: Try to get all books");
                var books = await _bookRepository.FindAll();

                var response = _mapper.Map <IList <BookDTO> >(books);
                foreach (var book in response)
                {
                    if (!string.IsNullOrEmpty(book.Image))
                    {
                        if (System.IO.File.Exists(GetImgPath(book.Image)))
                        {
                            byte[] imgBytes = System.IO.File.ReadAllBytes(GetImgPath(book.Image));
                            book.File = Convert.ToBase64String(imgBytes);
                        }
                    }
                }
                _logger.LogInfo($"{GetCallLocation()}:Success to get all books");
                return(Ok(response));
            }
            catch (Exception e)
            {
                _logger.LogInfo($"{ GetCallLocation()}: { e.Message} - {e.InnerException}");
                return(StatusCode(500, "Internal Error"));
            }
        }
Пример #3
0
        public async Task <IActionResult> Login([FromBody] UserDTO userDTO)
        {
            var location = GetControllerActionNames();

            try
            {
                var username = userDTO.Username;
                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} Succesfully authenticated");
                    var user = await _userManager.FindByNameAsync(username);

                    var tokenString = await GenerateJSONWebtoken(user);

                    return(Ok(new { token = tokenString }));
                }
                _logger.LogWarn($"{location}: {username} Not authenticated");
                return(Unauthorized(userDTO));
            }
            catch (Exception e)
            {
                return(InternalError($"{ e.Message} - { e.InnerException }"));
            }
        }
Пример #4
0
        public async Task <IActionResult> GetBooks()
        {
            var location = GetControllerActionNames();

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

                var response = _mapper.Map <IList <BookDTO> >(books);
                _logger.LogInfo($"{location}: Succesful");
                return(Ok(response));
            }
            catch (Exception e)
            {
                return(InternalError($"{location}: {e.Message} -{e.InnerException}"));
            }
        }
        public async Task <IActionResult> GetAuthors()
        {
            try
            {
                _logger.LogInfo("Try to get all authors");
                var authors = await _authorRepository.FindAll();

                var response = _mapper.Map <IList <AuthorDTO> >(authors);
                _logger.LogInfo("Success to get all authors");
                return(Ok(response));
            }
            catch (Exception e)
            {
                _logger.LogInfo($"{e.Message} - {e.InnerException}");
                return(StatusCode(500, "Internal Error"));
            }
        }
Пример #6
0
        public async Task <IActionResult> GetAuthors()
        {
            try
            {
                _logger.LogInfo("Attempted Get All Authors");
                var authors = await _authorRepository.FindAll();

                var response = _mapper.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 IEnumerable <string> Get()
 {
     _logger.LogInfo("Hit get in homecontroller");
     return(new string[] { "value1", "value2" });
 }
 public IEnumerable <string> Get()
 {
     _logger.LogInfo("Accessed Home - Info");
     return(new string[] { "value1", "value2" });
 }
Пример #9
0
 public IEnumerable <string> Get()
 {
     _logger.LogInfo("accessed Home Controller");
     return(new string[] { "value1", "value2" });
 }