Example #1
0
        public async Task <IActionResult> GetAuthor(int id)
        {
            try
            {
                _logger.LogInfo($"Trying to get all of Flys Book store Author by ID: {id}");
                var author = await _authorRepository.FindByID(id);

                if (author == null)
                {
                    _logger.LogWarn($"Author with id:{id} was not found");
                    return(NotFound());
                }
                var response = _mapper.Map <AuthorDTO>(author);
                _logger.LogInfo("Bingo got flys BookStore Author by ID with no issues");
                return(Ok(response));
            }
            catch (Exception e)
            {
                return(InternalError($"{e.Message } - {e.StackTrace }"));
            }
        }
Example #2
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}"));
            }
        }
Example #3
0
        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 }"));
            }
        }
        public async Task <IActionResult> GetBooksById(int id)
        {
            var location = GetControllerActionNames();

            try
            {
                _logger.LogInfo($"{location}: Attemped Call  for id {id}");
                var book = await _bookRepository.FindById(id);

                var response = _map.Map <BookDTO>(book);
                if (book == null)
                {
                    _logger.LogWarn($"{location} Faild to Find id {id}");
                    return(NotFound());
                }
                _logger.LogInfo($"{location}: Attempet Call Succesful");
                return(Ok(response));
            }
            catch (Exception e)
            {
                return(internalError($"{location}:{e.Message}-{e.InnerException}"));
            }
        }
Example #5
0
 public void Delete(int id)
 {
     _logger.LogWarn("This Is An Warrning");
 }