Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 public string Create(string token, Survey survey)
 {
     if (survey.Question.Length <= 100 && survey.God != null && userRepository.GetAuthorization(token))
     {
         survey.God = userRepository.Get(survey.God.Login);
         IDbConnection    db = new SqlConnection(ConnectionString);
         AnswerRepository answerRepository = new AnswerRepository(ConnectionString);
         db.Execute("INSERT INTO Survey (Question, IdCreator, AddResponse, SeveralAnswer) VALUES(@Question, @Id, @AddResponse, @SeveralAnswer)"
                    , new { survey.Question, survey.God.Id, survey.AddResponse, survey.SeveralAnswer });
         foreach (var answer in survey.Answers)
         {
             answer.Survey = Get(token, survey.Question).FirstOrDefault();
             answerRepository.Create(token, answer);
         }
         return("Success");
     }
     return("Fail");
 }
Esempio n. 4
0
 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);
     }
 }