Component Page /QuestionTag.cs (C#)
1: using System;  
2: using System.Collections.Generic;  
3: using Microsoft.ApplicationBlocks.Data;  
4: using System.Data.SqlClient;  
5: using System.Data;  
6:   
7: namespace QuizNetOnline.Logic  
8: {  
9:     [Serializable]  
10:     public class QuestionTag  
11:     {  
12:         public Tag Tag { get; set; }  
13:         public int QuestionID { get; set; }  
14:   
15:         public void Save()  
16:         {  
17:             ISqlWrapper isqlWrapper = new SqlWrapper();  
18:             string connStr = isqlWrapper.GetConnectionString();  
19:             const string sproc = "SaveTagQuestion";  
20:   
21:             var parameters = new SqlParameter[2];  
22:             parameters[0] = new SqlParameter("@QuestionID", QuestionID);  
23:             parameters[1] = new SqlParameter("@TagID", Tag.TagId);  
24:   
25:             try  
26:             {  
27:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
28:             }  
29:             catch (Exception ex)  
30:             {  
31:                 ErrorLog errorLog = new ErrorLog();  
32:                 errorLog.LogException("QuestionTagSave", ex, isqlWrapper);  
33:                 throw;  
34:             }  
35:         }  
36:   
37:         public List<QuestionTag> Load(int questionId)  
38:         {  
39:             return Load(questionId, null);  
40:         }  
41:   
42:         public void Delete()  
43:         {  
44:             ISqlWrapper isqlWrapper = new SqlWrapper();  
45:             string connStr = isqlWrapper.GetConnectionString();  
46:             const string sproc = "DeleteQuestionTag";  
47:   
48:             var parameters = new SqlParameter[2];  
49:             parameters[0] = new SqlParameter("@QuestionID", QuestionID);  
50:             parameters[1] = new SqlParameter("@TagID", Tag.TagId);  
51:   
52:   
53:             try  
54:             {  
55:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
56:   
57:                 QuestionID = 0;  
58:                 Tag = null;  
59:             }  
60:             catch (Exception ex)  
61:             {  
62:                 ErrorLog errorLog = new ErrorLog();  
63:                 errorLog.LogException("DeleteQuestionTag", ex, isqlWrapper);  
64:                 throw;  
65:             }  
66:         }  
67:   
68:         public List<QuestionTag> Load(int questionId, int? tagID)  
69:         {  
70:             var questionTags = new List<QuestionTag>();  
71:             ISqlWrapper isqlWrapper = new SqlWrapper();  
72:             string connStr = isqlWrapper.GetConnectionString();  
73:             const string sproc = "GetQuestionTag";  
74:   
75:             var parameters = new SqlParameter[2];  
76:             parameters[0] = new SqlParameter("@QuestionID", questionId);  
77:             parameters[1] = new SqlParameter("@TagID", tagID);  
78:   
79:   
80:             try  
81:             {  
82:                 DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];  
83:   
84:                 foreach (DataRow row in tbl.Rows)  
85:                 {  
86:                     var questionTag = new QuestionTag();  
87:                     var tag = new Tag  
88:                     {  
89:                         TagDesc = row["TagDesc"].ToString(),  
90:                         TagId = Convert.ToInt32(row["TagID"].ToString())  
91:                     };  
92:   
93:                     questionTag.Tag = tag;  
94:                     questionTag.QuestionID = Convert.ToInt32(row["QuestionID"].ToString());  
95:                     questionTags.Add(questionTag);  
96:   
97:                 }  
98:   
99:                 return questionTags;  
100:             }  
101:             catch (Exception ex)  
102:             {  
103:                 ErrorLog errorLog = new ErrorLog();  
104:                 errorLog.LogException("LoadQuestionTag", ex, isqlWrapper);  
105:                 throw;  
106:             }  
107:         }  
108:     }  
109: }  

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