Component Page /AdminMessage.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 AdminMessage : IAdminMessage  
11:     {  
12:   
13:         public int MessageID { get; set; }  
14:   
15:         public string AdminMessageText { get; set; }  
16:   
17:         public DateTime StartMessageDate { get; set; }  
18:   
19:         public DateTime EndMessageDate { get; set; }  
20:   
21:         public DateTime CreateMessageDate { get; set; }  
22:   
23:         public string CountryCode { get; set; }  
24:   
25:         public List<string> CountryCodes { get; set; }  
26:   
27:         public int UpdateAdminMessage(ISqlWrapper isqlWrapper, IAdminMessage adminMessageWrapper, ICountry country)  
28:         {  
29:             if (CountryCodes == null || country.GetCountries(new SqlWrapper()).Count == CountryCodes.Count)  
30:             {  
31:                 return adminMessageWrapper.SaveAdminMessage(isqlWrapper, null,new ErrorLog());  
32:             }  
33:             else  
34:             {  
35:                 foreach (string _country in CountryCodes)  
36:                 {  
37:                     adminMessageWrapper.SaveAdminMessage(isqlWrapper, _country, new ErrorLog());  
38:                 }  
39:                 return 0;  
40:             }  
41:         }  
42:   
43:         public int SaveAdminMessage(ISqlWrapper isqlWrapper, string country, IErrorLog errorLog)  
44:         {  
45:             string connStr = isqlWrapper.GetConnectionString();  
46:   
47:             const string sproc = "UpdateAdminMessage";  
48:             var parameters = new SqlParameter[4];  
49:             parameters[0] = new SqlParameter("AdminMessage", AdminMessageText);  
50:             parameters[1] = new SqlParameter("StartMessageDate", StartMessageDate);  
51:             parameters[2] = new SqlParameter("EndMessageDate", EndMessageDate);  
52:             parameters[3] = new SqlParameter("CountryCode", country);  
53:             try  
54:             {  
55:                 return isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
56:             }  
57:             catch (Exception ex)  
58:             {  
59:                 errorLog.LogException("UpdateAdminMessage", ex, isqlWrapper);  
60:                 throw;  
61:             }  
62:         }  
63:   
64:         public List<AdminMessage> GetAdminMessage(ISqlWrapper isqlWrapper)  
65:         {  
66:             return GetAdminMessage(null, isqlWrapper);  
67:         }  
68:   
69:         public List<AdminMessage> GetAdminMessage(string country,ISqlWrapper isqlWrapper)  
70:         {  
71:             List<AdminMessage> messages = new List<AdminMessage>();  
72:             AdminMessage message;  
73:   
74:             string connStr = isqlWrapper.GetConnectionString();  
75:   
76:             const string sproc = "GetAdminMessage";  
77:             var parameters = new SqlParameter[1];  
78:             parameters[0] = new SqlParameter("CountryCode", country);  
79:   
80:             try  
81:             {  
82:                 DataTable tbl = isqlWrapper.ExecuteDataset(connStr, CommandType.StoredProcedure, sproc, parameters).Tables[0];  
83:                 foreach(DataRow row in tbl.Rows)  
84:                 {  
85:                     message = new AdminMessage();  
86:                     message.MessageID = Convert.ToInt32(row["MessageID"].ToString());  
87:                     message.AdminMessageText = row["AdminMessage"].ToString();  
88:                     message.StartMessageDate = Convert.ToDateTime(row["StartMessageDate"].ToString());  
89:                     message.EndMessageDate = Convert.ToDateTime(row["EndMessageDate"].ToString());  
90:                     message.CreateMessageDate = string.IsNullOrEmpty(row["CreateMessageDate"].ToString()) ? DateTime.Now : Convert.ToDateTime(tbl.Rows[0]["CreateMessageDate"].ToString());  
91:                     message.CountryCode = row["CountryCode"].ToString();  
92:   
93:                     messages.Add(message);  
94:                 }  
95:   
96:                 return messages;  
97:   
98:             }  
99:             catch (Exception ex)  
100:             {  
101:                 ErrorLog errorLog = new ErrorLog();  
102:                 errorLog.LogException("GetAdminMessage", ex, isqlWrapper);  
103:                 throw;  
104:             }  
105:         }  
106:   
107:         public bool DeleteAll(ISqlWrapper isqlWrapper, IErrorLog errorLog)  
108:         {  
109:             return DeleteAdminMessage(isqlWrapper, null, errorLog);  
110:         }  
111:   
112:         public bool DeleteAdminMessage(ISqlWrapper isqlWrapper, int? messageID, IErrorLog errorLog)  
113:         {  
114:             string connStr = isqlWrapper.GetConnectionString();  
115:   
116:             const string sproc = "DeleteAdminMessage";  
117:             var parameters = new SqlParameter[1];  
118:             parameters[0] = new SqlParameter("MessageID", messageID);  
119:   
120:             try  
121:             {  
122:                 isqlWrapper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, sproc, parameters);  
123:                 return true;  
124:             }  
125:             catch (Exception ex)  
126:             {  
127:                 errorLog.LogException("DeleteAll", ex, isqlWrapper);  
128:                 throw;  
129:             }  
130:         }  
131:     }  
132: }  

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