Component Page /Tag.cs (C#)
1: using System;  
2: using System.Collections.Generic;  
3: using System.Linq;  
4: using Microsoft.ApplicationBlocks.Data;  
5: using System.Data.SqlClient;  
6: using System.Data;  
7:   
8: namespace QuizNetOnline.Logic  
9: {  
10:     [Serializable]  
11:     public class Tag  
12:     {  
13:         public int TagId { get; set; }  
14:         public string TagDesc { get; set; }  
15:   
16:         public void Save()  
17:         {  
18:             ISqlWrapper isqlWrapper = new SqlWrapper();  
19:             string connStr = isqlWrapper.GetConnectionString();  
20:             const string sproc = "SaveTag";  
21:   
22:             var parameters = new SqlParameter[2];  
23:             parameters[0] = new SqlParameter("@TagID", TagId);  
24:             parameters[1] = new SqlParameter("@TagDesc", TagDesc);  
25:   
26:             try  
27:             {  
28:                 Object obj = isqlWrapper.ExecuteScalar(connStr, CommandType.StoredProcedure, sproc, parameters);  
29:                 TagId = Convert.ToInt32(obj);  
30:             }  
31:             catch (Exception ex)  
32:             {  
33:                 ErrorLog errorLog = new ErrorLog();  
34:                 errorLog.LogException("QuestionTagSave", ex, isqlWrapper);  
35:                 throw;  
36:             }  
37:         }  
38:   
39:         public List<Tag> GetTags()  
40:         {  
41:             ISqlWrapper isqlWrapper = new SqlWrapper();  
42:             string connStr = isqlWrapper.GetConnectionString();  
43:             const string sproc = "GetTags";  
44:   
45:             try  
46:             {  
47:                 DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc).Tables[0];  
48:   
49:                 return (from DataRow row in tbl.Rows  
50:                         select new Tag  
51:                         {  
52:                             TagId = Convert.ToInt32(row["TagID"]),  
53:                             TagDesc = row["TagDesc"].ToString()  
54:                         }).ToList();  
55:             }  
56:             catch (Exception ex)  
57:             {  
58:                 ErrorLog errorLog = new ErrorLog();  
59:                 errorLog.LogException("GetTags", ex, isqlWrapper);  
60:                 throw;  
61:             }  
62:         }  
63:   
64:         public List<Topic> GetTagTopics(string tagDesc)  
65:         {  
66:             List<Topic> topics = new List<Topic>();  
67:   
68:             ISqlWrapper isqlWrapper = new SqlWrapper();  
69:             string connStr = isqlWrapper.GetConnectionString();  
70:             const string sproc = "GetTagTopics";  
71:   
72:             var parameters = new SqlParameter[1];  
73:             parameters[0] = new SqlParameter("@TagDesc", tagDesc);  
74:   
75:             try  
76:             {  
77:                 DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc,parameters).Tables[0];  
78:   
79:                 foreach(DataRow row in tbl.Rows)  
80:                 {  
81:                     topics.Add(new Topic(row["TopicCode"].ToString()));  
82:                 }  
83:   
84:                 return topics;  
85:             }  
86:             catch (Exception ex)  
87:             {  
88:                 ErrorLog errorLog = new ErrorLog();  
89:                 errorLog.LogException("GetTagTopics", ex, isqlWrapper);  
90:                 throw;  
91:             }  
92:         }  
93:     }  
94: }  

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