public Survey Get(string token, int id) { if (userRepository.GetAuthorization(token)) { AnswerRepository answerRepository = new AnswerRepository(ConnectionString); IDbConnection db = new SqlConnection(ConnectionString); var survey = db.Query <Survey>("SELECT * FROM Survey WHERE Id = @id", new { id }).FirstOrDefault(); survey.God = userRepository.Get(survey.IdCreator); survey.Answers = answerRepository.Get(token, survey).ToArray(); return(survey); } return(null); }
public List <Survey> Get(string token, string Question) { if (userRepository.GetAuthorization(token)) { IDbConnection db = new SqlConnection(ConnectionString); AnswerRepository answerRepository = new AnswerRepository(ConnectionString); var surveys = db.Query <Survey>("SELECT * FROM Survey WHERE Question = @Question", new { Question }).ToList(); foreach (var survey in surveys) { survey.God = userRepository.Get(survey.IdCreator); survey.Answers = answerRepository.Get(token, survey).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); } }