Component Page /Question.cs (C#)
1: using System;  
2: using System.Collections.Generic;  
3: using System.Linq;  
4: using Microsoft.ApplicationBlocks.Data;  
5: using QuiznetOnline.Data;  
6: using System.Data.SqlClient;  
7: using System.Data;  
8:   
9: namespace QuizNetOnline.Logic  
10: {  
11:     [Serializable]  
12:     public class Question  
13:     {  
14:         private static Question _instance;  
15:   
16:         public static Question Instance()  
17:         {  
18:             // Uses lazy initialization.  
19:             return _instance ?? (_instance = new Question());  
20:         }  
21:   
22:         public int QuestionId { get; set; }  
23:         public int QuestionOrderNumber { get; set; }  
24:         public Topic Topic { get; set; }  
25:         public QuestionImage Image { get; set; }  
26:         public string QuestionDesc { get; set; }  
27:         public int Answer { get; set; }  
28:         public string AnswerDesc { get; set; }  
29:         public string Explaination { get; set; }  
30:         public bool Approved { get; set; }  
31:         public DateTime CreationDate { get; set; }  
32:         public string Link { get; set; }  
33:         public int Correct { get; set; }  
34:         public int Incorrect { get; set; }  
35:         public string QuestionCreatedBy { get; set; }  
36:         public bool IsFree { get; set; }  
37:         public int Position { get; set; }  
38:         public List<Answer> Answers { get; set; }  
39:         public List<QuestionTag> Tags { get; set; }  
40:         public int? AuthorRating { get; set; }  
41:   
42:   
43:         public virtual List<Answer> PopulateAnswers(int? questionId, int? answerId, Answer answer, ISqlWrapper isqlWrapper)  
44:         {  
45:             List<Answer> answers = answer.LoadAnswers(questionId, answerId, isqlWrapper);  
46:             return answers;  
47:         }  
48:   
49:         public void Create()  
50:         {  
51:             ISqlWrapper isqlWrapper = new SqlWrapper();  
52:             string connStr = isqlWrapper.GetConnectionString();  
53:             const string sproc = "CreateQuestion";  
54:   
55:             var parameters = new SqlParameter[10];  
56:   
57:             parameters[0] = new SqlParameter("@TopicCode", Topic.TopicCode);  
58:             parameters[1] = new SqlParameter("@Question", QuestionDesc);  
59:             parameters[2] = new SqlParameter("@Answer", Answer);  
60:             parameters[3] = new SqlParameter("@Explaination", Explaination);  
61:             parameters[4] = new SqlParameter("@Link", Link);  
62:             parameters[5] = new SqlParameter("@QuestionCreatedBy", QuestionCreatedBy);  
63:             parameters[6] = new SqlParameter("@IsFree", IsFree);  
64:             parameters[7] = new SqlParameter("@Position", Position);  
65:             parameters[8] = new SqlParameter("@NewID", Convert.ToInt32(0)) { Direction = ParameterDirection.InputOutput };  
66:   
67:   
68:             try  
69:             {  
70:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
71:                 QuestionId = Convert.ToInt32(parameters[8].Value);  
72:   
73:                 if (Answers != null)  
74:                 {  
75:                     foreach (Answer answer in Answers)  
76:                     {  
77:                         answer.QuestionId = QuestionId;  
78:                         answer.Insert(isqlWrapper);  
79:                     }  
80:                 }  
81:             }  
82:             catch (Exception ex)  
83:             {  
84:                 ErrorLog errorLog = new ErrorLog();  
85:                 errorLog.LogException("CreateQuestion", ex, isqlWrapper);  
86:                 throw;  
87:             }  
88:         }  
89:   
90:         public void Save()  
91:         {  
92:             ISqlWrapper isqlWrapper = new SqlWrapper();  
93:             string connStr = isqlWrapper.GetConnectionString();  
94:             const string sproc = "UpdateQuestion";  
95:   
96:             SqlUpdateQuestion(isqlWrapper, connStr, sproc);  
97:   
98:             SqlDeleteTagQuestion(isqlWrapper, connStr, "DeleteTagQuestion");  
99:   
100:             foreach (QuestionTag tag in Tags)  
101:             {  
102:                 if (tag.Tag.TagId != 0)  
103:                 {  
104:                     SqlUpdateQuestionLog(isqlWrapper, connStr, "UpdateQuestionLog", tag.Tag.TagId);  
105:                 }  
106:             }  
107:         }  
108:   
109:         private void SqlUpdateQuestionLog(ISqlWrapper isqlWrapper, string connStr, string sproc, int tagId)  
110:         {  
111:             var parameters = new SqlParameter[2];  
112:   
113:             parameters[0] = new SqlParameter("@QuestionID", QuestionId);  
114:             parameters[1] = new SqlParameter("@TagID", tagId);  
115:   
116:   
117:             try  
118:             {  
119:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
120:             }  
121:             catch (Exception ex)  
122:             {  
123:                 ErrorLog errorLog = new ErrorLog();  
124:                 errorLog.LogException("SqlUpdateQuestionLog", ex, isqlWrapper);  
125:                 throw;  
126:             }  
127:         }  
128:   
129:         private void SqlUpdateQuestion(ISqlWrapper isqlWrapper, string connStr, string sproc)  
130:         {  
131:             var parameters = new SqlParameter[13];  
132:   
133:             parameters[0] = new SqlParameter("@QuestionID", QuestionId);  
134:             parameters[1] = new SqlParameter("@TopicCode", Topic.TopicCode);  
135:             parameters[2] = new SqlParameter("@Question", QuestionDesc);  
136:             parameters[3] = new SqlParameter("@Answer", Answer.ToString());  
137:             parameters[4] = new SqlParameter("@Explaination", Explaination);  
138:             parameters[5] = new SqlParameter("@Approved", Approved);  
139:             parameters[6] = new SqlParameter("@CreationDate", CreationDate);  
140:             parameters[7] = new SqlParameter("@Link", Link);  
141:             parameters[8] = new SqlParameter("@Correct", Correct);  
142:             parameters[9] = new SqlParameter("@Incorrect", Incorrect);  
143:             parameters[10] = new SqlParameter("@QuestionCreatedBy", QuestionCreatedBy);  
144:             parameters[11] = new SqlParameter("@IsFree", IsFree);  
145:             parameters[12] = new SqlParameter("@Position", Position);  
146:   
147:   
148:             try  
149:             {  
150:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
151: There is a limit of 150 source code lines in the evaluation version
152: There is a limit of 150 source code lines in the evaluation version
153: There is a limit of 150 source code lines in the evaluation version
154: There is a limit of 150 source code lines in the evaluation version
155: There is a limit of 150 source code lines in the evaluation version
156: There is a limit of 150 source code lines in the evaluation version
157: There is a limit of 150 source code lines in the evaluation version
158: There is a limit of 150 source code lines in the evaluation version
159: There is a limit of 150 source code lines in the evaluation version
160: There is a limit of 150 source code lines in the evaluation version
161: There is a limit of 150 source code lines in the evaluation version
162: There is a limit of 150 source code lines in the evaluation version
163: There is a limit of 150 source code lines in the evaluation version
164: There is a limit of 150 source code lines in the evaluation version
165: There is a limit of 150 source code lines in the evaluation version
166: There is a limit of 150 source code lines in the evaluation version
167: There is a limit of 150 source code lines in the evaluation version
168: There is a limit of 150 source code lines in the evaluation version
169: There is a limit of 150 source code lines in the evaluation version
170: There is a limit of 150 source code lines in the evaluation version
171: There is a limit of 150 source code lines in the evaluation version
172: There is a limit of 150 source code lines in the evaluation version
173: There is a limit of 150 source code lines in the evaluation version
174: There is a limit of 150 source code lines in the evaluation version
175: There is a limit of 150 source code lines in the evaluation version
176: There is a limit of 150 source code lines in the evaluation version
177: There is a limit of 150 source code lines in the evaluation version
178: There is a limit of 150 source code lines in the evaluation version
179: There is a limit of 150 source code lines in the evaluation version
180: There is a limit of 150 source code lines in the evaluation version
181: There is a limit of 150 source code lines in the evaluation version
182: There is a limit of 150 source code lines in the evaluation version
183: There is a limit of 150 source code lines in the evaluation version
184: There is a limit of 150 source code lines in the evaluation version
185: There is a limit of 150 source code lines in the evaluation version
186: There is a limit of 150 source code lines in the evaluation version
187: There is a limit of 150 source code lines in the evaluation version
188: There is a limit of 150 source code lines in the evaluation version
189: There is a limit of 150 source code lines in the evaluation version
190: There is a limit of 150 source code lines in the evaluation version
191: There is a limit of 150 source code lines in the evaluation version
192: There is a limit of 150 source code lines in the evaluation version
193: There is a limit of 150 source code lines in the evaluation version
194: There is a limit of 150 source code lines in the evaluation version
195: There is a limit of 150 source code lines in the evaluation version
196: There is a limit of 150 source code lines in the evaluation version
197: There is a limit of 150 source code lines in the evaluation version
198: There is a limit of 150 source code lines in the evaluation version
199: There is a limit of 150 source code lines in the evaluation version
200: There is a limit of 150 source code lines in the evaluation version
201: There is a limit of 150 source code lines in the evaluation version
202: There is a limit of 150 source code lines in the evaluation version
203: There is a limit of 150 source code lines in the evaluation version
204: There is a limit of 150 source code lines in the evaluation version
205: There is a limit of 150 source code lines in the evaluation version
206: There is a limit of 150 source code lines in the evaluation version
207: There is a limit of 150 source code lines in the evaluation version
208: There is a limit of 150 source code lines in the evaluation version
209: There is a limit of 150 source code lines in the evaluation version
210: There is a limit of 150 source code lines in the evaluation version
211: There is a limit of 150 source code lines in the evaluation version
212: There is a limit of 150 source code lines in the evaluation version
213: There is a limit of 150 source code lines in the evaluation version
214: There is a limit of 150 source code lines in the evaluation version
215: There is a limit of 150 source code lines in the evaluation version
216: There is a limit of 150 source code lines in the evaluation version
217: There is a limit of 150 source code lines in the evaluation version
218: There is a limit of 150 source code lines in the evaluation version
219: There is a limit of 150 source code lines in the evaluation version
220: There is a limit of 150 source code lines in the evaluation version
221: There is a limit of 150 source code lines in the evaluation version
222: There is a limit of 150 source code lines in the evaluation version
223: There is a limit of 150 source code lines in the evaluation version
224: There is a limit of 150 source code lines in the evaluation version
225: There is a limit of 150 source code lines in the evaluation version
226: There is a limit of 150 source code lines in the evaluation version
227: There is a limit of 150 source code lines in the evaluation version
228: There is a limit of 150 source code lines in the evaluation version
229: There is a limit of 150 source code lines in the evaluation version
230: There is a limit of 150 source code lines in the evaluation version
231: There is a limit of 150 source code lines in the evaluation version
232: There is a limit of 150 source code lines in the evaluation version
233: There is a limit of 150 source code lines in the evaluation version
234: There is a limit of 150 source code lines in the evaluation version
235: There is a limit of 150 source code lines in the evaluation version
236: There is a limit of 150 source code lines in the evaluation version
237: There is a limit of 150 source code lines in the evaluation version
238: There is a limit of 150 source code lines in the evaluation version
239: There is a limit of 150 source code lines in the evaluation version
240: There is a limit of 150 source code lines in the evaluation version
241: There is a limit of 150 source code lines in the evaluation version
242: There is a limit of 150 source code lines in the evaluation version
243: There is a limit of 150 source code lines in the evaluation version
244: There is a limit of 150 source code lines in the evaluation version
245: There is a limit of 150 source code lines in the evaluation version
246: There is a limit of 150 source code lines in the evaluation version
247: There is a limit of 150 source code lines in the evaluation version
248: There is a limit of 150 source code lines in the evaluation version
249: There is a limit of 150 source code lines in the evaluation version
250: There is a limit of 150 source code lines in the evaluation version
251: There is a limit of 150 source code lines in the evaluation version
252: There is a limit of 150 source code lines in the evaluation version
253: There is a limit of 150 source code lines in the evaluation version
254: There is a limit of 150 source code lines in the evaluation version
255: There is a limit of 150 source code lines in the evaluation version
256: There is a limit of 150 source code lines in the evaluation version
257: There is a limit of 150 source code lines in the evaluation version
258: There is a limit of 150 source code lines in the evaluation version
259: There is a limit of 150 source code lines in the evaluation version
260: There is a limit of 150 source code lines in the evaluation version
261: There is a limit of 150 source code lines in the evaluation version
262: There is a limit of 150 source code lines in the evaluation version
263: There is a limit of 150 source code lines in the evaluation version
264: There is a limit of 150 source code lines in the evaluation version
265: There is a limit of 150 source code lines in the evaluation version
266: There is a limit of 150 source code lines in the evaluation version
267: There is a limit of 150 source code lines in the evaluation version
268: There is a limit of 150 source code lines in the evaluation version
269: There is a limit of 150 source code lines in the evaluation version
270: There is a limit of 150 source code lines in the evaluation version
271: There is a limit of 150 source code lines in the evaluation version
272: There is a limit of 150 source code lines in the evaluation version
273: There is a limit of 150 source code lines in the evaluation version
274: There is a limit of 150 source code lines in the evaluation version
275: There is a limit of 150 source code lines in the evaluation version
276: There is a limit of 150 source code lines in the evaluation version
277: There is a limit of 150 source code lines in the evaluation version
278: There is a limit of 150 source code lines in the evaluation version
279: There is a limit of 150 source code lines in the evaluation version
280: There is a limit of 150 source code lines in the evaluation version
281: There is a limit of 150 source code lines in the evaluation version
282: There is a limit of 150 source code lines in the evaluation version
283: There is a limit of 150 source code lines in the evaluation version
284: There is a limit of 150 source code lines in the evaluation version
285: There is a limit of 150 source code lines in the evaluation version
286: There is a limit of 150 source code lines in the evaluation version
287: There is a limit of 150 source code lines in the evaluation version
288: There is a limit of 150 source code lines in the evaluation version
289: There is a limit of 150 source code lines in the evaluation version
290: There is a limit of 150 source code lines in the evaluation version
291: There is a limit of 150 source code lines in the evaluation version
292: There is a limit of 150 source code lines in the evaluation version
293: There is a limit of 150 source code lines in the evaluation version
294: There is a limit of 150 source code lines in the evaluation version
295: There is a limit of 150 source code lines in the evaluation version
296: There is a limit of 150 source code lines in the evaluation version
297: There is a limit of 150 source code lines in the evaluation version
298: There is a limit of 150 source code lines in the evaluation version
299: There is a limit of 150 source code lines in the evaluation version

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.