コード例 #1
0
        public Survey GetSurvey(long id)
        {
            using (var db = new SqlConnection(_connectionStrings.ConsentForm))
            {
                var survey = db.Query <Survey>(SurveyDbQuery.GetSurvey(), new { Id = id }).FirstOrDefault();

                var topics = db.Query <Topic>(SurveyDbQuery.GetTopic(), new { SurveyId = id }).ToList();

                var topicIdList = topics.Select(t => t.Id).Distinct();

                var subTopics = db.Query <SubTopic>(SurveyDbQuery.GetSubTopic(), new { @TopicId = topicIdList });

                foreach (var topic in topics)
                {
                    foreach (var subTopic in subTopics)
                    {
                        if (topic.Id == subTopic.TopicId)
                        {
                            topic.SubTopics.Add(subTopic);
                        }
                    }
                }

                survey.Topics = topics;

                return(survey);
            }
        }
コード例 #2
0
        public Survey GetSurveyChild(long id)
        {
            using (var db = new SqlConnection(_connectionStrings.ConsentForm))
            {
                var surveyDictionary = new Dictionary <int, Survey>();

                var result = db.Query <Survey, Topic, SubTopic, Survey>(SurveyDbQuery.GetSurveyChild(),
                                                                        (survey, topic, subTopic) =>
                {
                    //topic.SubTopics.Add(subTopic);
                    //survey.Topics.Add(topic);


                    //return survey;

                    if (!surveyDictionary.TryGetValue(survey.Id, out Survey surveyEntry))
                    {
                        surveyEntry        = survey;
                        surveyEntry.Topics = new List <Topic>();
                        surveyDictionary.Add(surveyEntry.Id, surveyEntry);
                    }

                    if (survey.Id == topic.SurveyId)
                    {
                        surveyEntry.Topics.Add(topic);
                    }

                    return(surveyEntry);
                }, new { id }, splitOn: "id").FirstOrDefault();

                return(result);
            }
        }
コード例 #3
0
 public void DeleteSurvey(long id)
 {
     using (var db = new SqlConnection(_connectionStrings.ConsentForm))
     {
         db.Query(SurveyDbQuery.DeleteSurvey(), new { Id = id });
     }
 }
コード例 #4
0
 public long AddSurvey(Survey survey)
 {
     using (var db = new SqlConnection(_connectionStrings.ConsentForm))
     {
         return(db.Query <long>(SurveyDbQuery.AddSurvey(), new { Name = survey.Name }).SingleOrDefault());
     }
 }
コード例 #5
0
 public void UpdateSurvey(Survey survey)
 {
     using (var db = new SqlConnection(_connectionStrings.ConsentForm))
     {
         db.Execute(SurveyDbQuery.UpdateSuervey(), new { survey.Name });
     }
 }
コード例 #6
0
 public bool SurveyExists(long id)
 {
     using (var db = new SqlConnection(_connectionStrings.ConsentForm))
     {
         return(db.ExecuteScalar <bool>(SurveyDbQuery.SurveyExits(), new { id }));
     }
 }
コード例 #7
0
 public List <Survey> GetSurveys()
 {
     using (var db = new SqlConnection(_connectionStrings.ConsentForm))
     {
         return(db.Query <Survey>(SurveyDbQuery.GetSurveys()).ToList());
     }
 }