Example #1
0
 public ActionResult <IEnumerable <ViewModels.State> > ListAll()
 {
     try
     {
         var dataModels = _repository.ListAll();
         var viewModels = _mapper.Map <List <ViewModels.State> >(dataModels);
         return(viewModels);
     }
     catch (Exception ex)
     {
         var messageResponse = _errorGenerator.GetMessageResponse <DataModels.State>(ActionType.List, exception: ex);
         Log.Error(messageResponse.LogTemplate, messageResponse.Message);
         throw new Exception(messageResponse.Message);
     }
 }
Example #2
0
        public ActionResult <List <Article> > Search(SearchArticleInput input)
        {
            try
            {
                var articles = _repositoryFactory.ArticleRepository.Search(input).ToList();
                var authors  = _repositoryFactory.AuthorRepository.Search(input);
                foreach (var author in authors)
                {
                    var articlesOfAuthor = _repositoryFactory.ArticleRepository.Search(new SearchArticleInput {
                        AuthorId = author.Id
                    });
                    foreach (var item in articlesOfAuthor)
                    {
                        if (articles.Any(a => a.Id != item.Id))
                        {
                            articles.Add(item);
                        }
                    }
                }

                var viewModels = _mapper.Map <List <Article> >(articles);
                viewModels.ForEach(viewModel =>
                {
                    getArticleDetails(viewModel);
                });
                return(viewModels);
            }
            catch (Exception ex)
            {
                var messageResponse = _errorGenerator.GetMessageResponse <Article, SearchArticleInput>(ActionType.List, input, ex);
                Log.Error(messageResponse.LogTemplate, messageResponse.Message, input);
                throw new Exception(messageResponse.Message);
            }
        }
 public ActionResult <IEnumerable <Article> > ListAll()
 {
     try
     {
         var dataModels = _articleRepository.ListAll();
         var viewModels = _mapper.Map <List <Article> >(dataModels);
         viewModels.ForEach(viewModel =>
         {
             // getArticleDetails(viewModel);
         });
         return(viewModels);
     }
     catch (Exception ex)
     {
         var messageResponse = _errorGenerator.GetMessageResponse <Article>(ActionType.List, exception: ex);
         Log.Error(messageResponse.LogTemplate, messageResponse.Message);
         throw new Exception(messageResponse.Message);
     }
 }