public List <Survey> GetSurveys(string token) { if (userRepository.GetAuthorization(token)) { IDbConnection db = new SqlConnection(ConnectionString); AnswerRepository answerRepository = new AnswerRepository(ConnectionString); VoteRepository voteRepository = new VoteRepository(ConnectionString); var surveys = db.Query <Survey>("SELECT * FROM Survey").ToList(); foreach (var survey in surveys) { survey.God = userRepository.Get(survey.IdCreator); survey.Answers = answerRepository.Get(token, survey).ToArray(); survey.Answers = voteRepository.Get(token, survey.Answers).ToArray(); } return(surveys); } return(null); }
public List <Survey> Get(string token, User God) { if (God.Login != null && userRepository.GetAuthorization(token)) { IDbConnection db = new SqlConnection(ConnectionString); AnswerRepository answerRepository = new AnswerRepository(ConnectionString); VoteRepository voteRepository = new VoteRepository(ConnectionString); God = userRepository.Get(God.Login); var surveys = db.Query <Survey>("SELECT * FROM Survey WHERE IdCreator = @Id", new { God.Id }).ToList(); foreach (var survey in surveys) { survey.Answers = answerRepository.Get(token, survey).ToArray(); survey.Answers = voteRepository.Get(token, survey.Answers).ToArray(); } return(surveys); } else { return(null); } }