public async Task <ResultResponse <IEnumerable <QuestionDto> > > GetQuestionListAsync(int userId) { try { var user = await _usersRepository.GetAsync(userId); if (user == null) { return(ResultResponse <IEnumerable <QuestionDto> > .GetBadResponse(StatusCode.NotFound, "Пользователь не найден")); } var questionViews = await _questionsViewRepository.GetAsync("WHERE is_active = TRUE"); var questionMiddleDtos = _mapper.Map <IEnumerable <QuestionFullDto> >(questionViews); // Конвертируем в промежуточный ДТО var questionDtos = _mapper.Map <IEnumerable <QuestionDto> >(questionMiddleDtos); foreach (var q in questionDtos) { q.IsVoted = await IsUserVotedInQuestion(userId, q.Id); } return(ResultResponse <IEnumerable <QuestionDto> > .GetSuccessResponse(questionDtos)); } catch (Exception ex) { _progressLogger.Error(ex, new { userId }, GetType().Name, nameof(GetQuestionListAsync)); return(ResultResponse <IEnumerable <QuestionDto> > .GetInternalServerErrorResponse()); } }
public async Task <ResultResponse <IEnumerable <AdvertisementDto> > > GetAdvertisementListAsync() { try { var advertisementViews = await _advertisementViewsRepository.GetAsync("WHERE is_active = TRUE"); var advertisementDtos = _mapper.Map <IEnumerable <AdvertisementDto> >(advertisementViews); return(ResultResponse <IEnumerable <AdvertisementDto> > .GetSuccessResponse(advertisementDtos)); } catch (Exception ex) { _progressLogger.Error(ex, null, GetType().Name, nameof(GetAdvertisementListAsync)); return(ResultResponse <IEnumerable <AdvertisementDto> > .GetInternalServerErrorResponse()); } }
public async Task <ResultResponse <DocumentDto> > GetDocumentAsync(int documentId) { try { var document = (await _documentViewsRepository.GetAsync($"WHERE id = {documentId} AND is_active = TRUE")).FirstOrDefault(); if (document == null) { return(ResultResponse <DocumentDto> .GetBadResponse(StatusCode.NotFound, "Не найден файл с указанным идентификатором")); } var documentDto = _mapper.Map <DocumentDto>(document); return(ResultResponse <DocumentDto> .GetSuccessResponse(documentDto)); } catch (Exception ex) { _progressLogger.Error(ex, documentId, GetType().Name, nameof(GetDocumentAsync)); return(ResultResponse <DocumentDto> .GetInternalServerErrorResponse()); } }
public async Task <IResponseOutput> GetAsync(long id) { var result = await _viewRepository.GetAsync <ViewGetOutput>(id); return(ResponseOutput.Ok(result)); }