public SurveyDirectory GetDirectoryDetailStyle(int id) { var cacheModel = _cacheManager.Get <SurveyDirectory>(string.Format(SurveyConfig.DIRDETAILSTYLE, id)); if (cacheModel == null) { var surveyDirectory = _dbQuery.Query <SurveyDirectory, SurveyDetail, SurveyStyle, SurveyDirectory>("SELECT a.*,b.*,c.* FROM dbo.SurveyDirectory a INNER JOIN dbo.SurveyDetail b ON a.id = b.DirId LEFT JOIN dbo.SurveyStyle c ON a.id =c.DirId AND c.IsValid=1 WHERE a.id = @Id AND a.IsValid = 1", (dir, detail, style) => { dir.SurveyDetail = detail; dir.SurveyStyle = style ?? new SurveyStyle(); return(dir); }, new { Id = id }, splitOn: "id").FirstOrDefault(); if (surveyDirectory != null) { surveyDirectory.Questions = _questionservices.Get(surveyDirectory.Id); } if (surveyDirectory.SurveyState > 0) { _cacheManager.Set(string.Format(SurveyConfig.DIRDETAILSTYLE, id), surveyDirectory, 60 * 24); } return(surveyDirectory); } return(cacheModel); }
public Question Get(long questionid) { var questions = _dbQuery.Query <Question, QuestionLogic, Question>("SELECT q.id , q.Uid , q.DirId , q.QuName , q.QuTitle , q.QuNote , q.Keywords , q.QuType , q.Tag , q.OrderById , q.QuTag , q.ParentQuId , q.YesnoOption , q.IsRequired , q.CheckType , q.ParamInt01 , q.ParamInt02 , q.CopyFromId , q.Hv , q.RandOrder , q.CellCount , q.ContactsAttr , q.ContactsField , q.AnswerInputWidth , q.AnswerInputRow , q.CreateDate , q.IsValid ,l.id, l.QuId , l.Uid , l.QuItemId , l.SkipToQuId , l.LogicType , l.GeLe , l.ScoreNum , l.CreateDate , l.IsValid FROM dbo.Question q LEFT JOIN dbo.QuestionLogic l ON q.id = l.QuId WHERE q.Id = @quid AND q.IsValid = 1 ORDER BY q.OrderById ASC;", (question, logic) => { if (logic != null) { question.QuestionLogics.Add(logic); } return(question); }, new { quid = questionid }, splitOn: "id").ToList(); if (questions.Count > 0) { bool hasQueryChenGroup = false; var group = from p in questions group p by p.QuType into g select g; foreach (IGrouping <QuType, Question> groupItem in group) { switch (groupItem.Key) { case QuType.RADIO: var radiolist = _dbQuery.QueryList <QuestionRadio>("SELECT * FROM dbo.QuestionRadio WHERE QuId in @quid AND IsValid=1", new { quid = groupItem.Select(p => p.Id) }).ToList(); radiolist.ForEach(p => p.OptionName = Utils.HtmlDecode(p.OptionName)); foreach (Question question in groupItem) { question.QuName = Utils.HtmlDecode(question.QuName); question.QuRadios.AddRange(radiolist.Where(p => p.QuId == question.Id)); } break; case QuType.CHECKBOX: var checklist = _dbQuery.QueryList <QuestionCheckbox>("SELECT * FROM dbo.QuestionCheckbox WHERE QuId in @quid AND IsValid=1", new { quid = groupItem.Select(p => p.Id) }).ToList(); checklist.ForEach(p => p.OptionName = Utils.HtmlDecode(p.OptionName)); foreach (Question question in groupItem) { question.QuName = Utils.HtmlDecode(question.QuName); question.QuCheckboxes.AddRange(checklist.Where(p => p.QuId == question.Id)); } break; case QuType.SCORE: var scorelist = _dbQuery.QueryList <QuestionScore>("SELECT * FROM dbo.QuestionScore WHERE QuId in @quid AND IsValid=1", new { quid = groupItem.Select(p => p.Id) }).ToList(); scorelist.ForEach(p => p.OptionName = Utils.HtmlDecode(p.OptionName)); foreach (Question question in groupItem) { question.QuName = Utils.HtmlDecode(question.QuName); question.QuScores.AddRange(scorelist.Where(p => p.QuId == question.Id)); } break; case QuType.ORDERQU: var orderbylist = _dbQuery.QueryList <QuestionOrderby>("SELECT * FROM dbo.QuestionOrderby WHERE QuId in @quid AND IsValid=1", new { quid = groupItem.Select(p => p.Id) }).ToList(); orderbylist.ForEach(p => p.OptionName = Utils.HtmlDecode(p.OptionName)); foreach (Question question in groupItem) { question.QuName = Utils.HtmlDecode(question.QuName); question.QuOrderbies.AddRange(orderbylist.Where(p => p.QuId == question.Id)); } break; case QuType.MULTIFILLBLANK: var mulitFillBlanklist = _dbQuery.QueryList <QuestionMultiFillblank>("SELECT * FROM dbo.QuestionMultiFillblank WHERE QuId in @quid AND IsValid=1", new { quid = groupItem.Select(p => p.Id) }).ToList(); mulitFillBlanklist.ForEach(p => p.OptionName = Utils.HtmlDecode(p.OptionName)); foreach (Question question in groupItem) { question.QuName = Utils.HtmlDecode(question.QuName); question.QuMultiFillblanks.AddRange(mulitFillBlanklist.Where(p => p.QuId == question.Id)); } break; case QuType.CHENRADIO: case QuType.CHENCHECKBOX: case QuType.CHENSCORE: case QuType.CHENFBK: if (hasQueryChenGroup) { continue; } var multiItems = questions.Where(q => q.QuType == QuType.CHENRADIO || q.QuType == QuType.CHENCHECKBOX || q.QuType == QuType.CHENSCORE || q.QuType == QuType.CHENFBK).ToList(); var rowlist = _dbQuery.QueryList <QuestionChenRow>("SELECT * FROM dbo.QuestionChenRow WHERE QuId in @quid AND IsValid=1", new { quid = multiItems.Select(p => p.Id) }).ToList(); rowlist.ForEach(p => p.OptionName = Utils.HtmlDecode(p.OptionName)); var columnlist = _dbQuery.QueryList <QuestionChenColumn>("SELECT * FROM dbo.QuestionChenColumn WHERE QuId in @quid AND IsValid=1", new { quid = multiItems.Select(p => p.Id) }).ToList(); columnlist.ForEach(p => p.OptionName = Utils.HtmlDecode(p.OptionName)); foreach (Question question in multiItems) { question.QuName = Utils.HtmlDecode(question.QuName); question.QuChenRows.AddRange(rowlist.Where(p => p.QuId == question.Id)); question.QuChenColumns.AddRange(columnlist.Where(p => p.QuId == question.Id)); } hasQueryChenGroup = true; break; case QuType.PAGETAG: case QuType.PARAGRAPH: case QuType.FILLBLANK: foreach (Question question in groupItem) { question.QuName = Utils.HtmlDecode(question.QuName); } break; } } } return(questions.FirstOrDefault()); }