Component Page /QuestionRating.cs (C#)
1: using System;  
2: using Microsoft.ApplicationBlocks.Data;  
3: using System.Data.SqlClient;  
4: using System.Data;  
5: using System.Collections.Generic;  
6:   
7: namespace QuizNetOnline.Logic  
8: {  
9:     [Serializable]  
10:     public class QuestionRating  
11:     {  
12:         private DateTime _insertDate;  
13:         private int _questionID;  
14:   
15:         private int _rating;  
16:   
17:         private string _userName;  
18:   
19:         public int QuestionID  
20:         {  
21:             get { return _questionID; }  
22:             set { _questionID = value; }  
23:         }  
24:   
25:         public int Rating  
26:         {  
27:             get { return _rating; }  
28:             set { _rating = value; }  
29:         }  
30:   
31:         public string UserName  
32:         {  
33:             get { return _userName; }  
34:             set { _userName = value; }  
35:         }  
36:   
37:         public DateTime InsertDate  
38:         {  
39:             get { return _insertDate; }  
40:             set { _insertDate = value; }  
41:         }  
42:   
43:         public void SaveAuthorRating()  
44:         {  
45:             ISqlWrapper isqlWrapper = new SqlWrapper();  
46:             string connStr = isqlWrapper.GetConnectionString();  
47:             const string sproc = "SaveQuestionRatingAuthor";  
48:   
49:             var parameters = new SqlParameter[3];  
50:   
51:             parameters[0] = new SqlParameter("@QuestionID", QuestionID);  
52:             parameters[1] = new SqlParameter("@Username", UserName);  
53:             parameters[2] = new SqlParameter("@Rating", Rating);  
54:   
55:             try  
56:             {  
57:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
58:   
59:             }  
60:             catch (Exception ex)  
61:             {  
62:                 ErrorLog errorLog = new ErrorLog();  
63:                 errorLog.LogException("SaveAuthorRating", ex, isqlWrapper);  
64:                 throw;  
65:             }  
66:         }  
67:   
68:         public List<QuestionRating> GetQuestionRating()  
69:         {  
70:             List<QuestionRating> questionRatings = new List<QuestionRating>();  
71:             ISqlWrapper isqlWrapper = new SqlWrapper();  
72:             string connStr = isqlWrapper.GetConnectionString();  
73:             const string sproc = "GetQuestionRating";  
74:   
75:             try  
76:             {  
77:                 DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc).Tables[0];  
78:   
79:                 if (tbl.Rows.Count > 0)  
80:                 {  
81:                     QuestionID = Convert.ToInt32(tbl.Rows[0]["QuestionID"]);  
82:                     Rating = Convert.ToInt32(tbl.Rows[0]["Rating"]);  
83:                     UserName = tbl.Rows[0]["UserName"].ToString();  
84:                     InsertDate = Convert.ToDateTime(tbl.Rows[0]["InsertDate"].ToString());  
85:                     questionRatings.Add(this);  
86:                 }  
87:   
88:                 return questionRatings;  
89:             }  
90:             catch (Exception ex)  
91:             {  
92:                 ErrorLog errorLog = new ErrorLog();  
93:                 errorLog.LogException("GetQuestionRating", ex, isqlWrapper);  
94:                 throw;  
95:             }  
96:         }  
97:   
98:         public void GetAuthorRating(int questionID, string userName)  
99:         {  
100:             ISqlWrapper isqlWrapper = new SqlWrapper();  
101:             string connStr = isqlWrapper.GetConnectionString();  
102:             const string sproc = "GetQuestionRatingAuthor";  
103:   
104:             var parameters = new SqlParameter[2];  
105:   
106:             parameters[0] = new SqlParameter("@QuestionID", questionID);  
107:             parameters[1] = new SqlParameter("@Username", userName);  
108:   
109:             try  
110:             {  
111:                 DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];  
112:   
113:                 if (tbl.Rows.Count > 0)  
114:                 {  
115:                     QuestionID = Convert.ToInt32(tbl.Rows[0]["QuestionID"]);  
116:                     Rating = Convert.ToInt32(tbl.Rows[0]["Rating"]);  
117:                     UserName = tbl.Rows[0]["UserName"].ToString();  
118:                     InsertDate = Convert.ToDateTime(tbl.Rows[0]["InsertDate"].ToString());  
119:                 }  
120:             }  
121:             catch (Exception ex)  
122:             {  
123:                 ErrorLog errorLog = new ErrorLog();  
124:                 errorLog.LogException("GetAuthorRating", ex, isqlWrapper);  
125:                 throw;  
126:             }  
127:         }  
128:   
129:         public virtual void Insert(ISqlWrapper iSqlWrapper)  
130:         {  
131:             string connStr = iSqlWrapper.GetConnectionString();  
132:             const string sproc = "InsertQuestionRating";  
133:   
134:             var parameters = new SqlParameter[3];  
135:   
136:             parameters[0] = new SqlParameter("@QuestionID", QuestionID);  
137:             parameters[1] = new SqlParameter("@Rating", Rating);  
138:             parameters[2] = new SqlParameter("@Username", UserName);  
139:   
140:             try  
141:             {  
142:                 iSqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
143:             }  
144:             catch (Exception ex)  
145:             {  
146:                 ErrorLog errorLog = new ErrorLog();  
147:                 errorLog.LogException("QuestionRating.Insert", ex, iSqlWrapper);  
148:                 throw;  
149:             }  
150:         }  
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

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