Esempio n. 1
0
        private void readAuthor(Article article)
        {
            var author = _repositoryFactory.AuthorRepository.Read(article.AuthorId);

            if (author == null)
            {
                throw new Exception(_errorGenerator.GetExceptionResponse <Article, Author>(ActionType.Create));
            }
            article.Author = _mapper.Map <Author>(author);
        }
Esempio n. 2
0
        public ActionResult <Author> Delete(long id)
        {
            try
            {
                if (_repository.Delete(id) != EntityStates.Deleted)
                {
                    throw new Exception(_errorGenerator.GetExceptionResponse <Author>(ActionType.Delete));
                }

                var messageResponse = _errorGenerator.GetMessageResponse <Author>(ActionType.Delete, id, success: true);
                Log.Warning(messageResponse.LogTemplate, messageResponse.Message);
                return(new JsonResult(new { messageResponse.Message }));
            }
            catch (Exception ex)
            {
                var input           = new { Id = id };
                var messageResponse = _errorGenerator.GetMessageResponse <Author, object>(ActionType.Delete, input, exception: ex);
                Log.Error(messageResponse.LogTemplate, messageResponse.Message, input);
                throw new Exception(messageResponse.Message);
            }
        }