Commit ec2d93bd3b4f3ed463b77dccfca8b661e79b8460

Authored by Utkarsh Singh
1 parent 9801aa67

Committing update restructured code files

400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
... ... @@ -30,7 +30,7 @@ namespace AIAHTML5.API.Models
30 30 conn.Open();
31 31 }
32 32  
33   - protected static DataSet GetSQLData(string commandText, bool isSp)
  33 + protected static DataSet GetDataFromStoredProcedure(string commandText)
34 34 {
35 35 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
36 36 logger.Debug(" Inside GetSQLData for command text = " + commandText);
... ... @@ -38,15 +38,8 @@ namespace AIAHTML5.API.Models
38 38 try
39 39 {
40 40 conn = new SqlConnection(dbConnectionString);
41   - if (isSp)
42   - {
43   - cmd = new SqlCommand(commandText, conn);
44   - cmd.CommandType = CommandType.StoredProcedure;
45   - }
46   - else
47   - {
48   - cmd = new SqlCommand(commandText, conn);
49   - }
  41 + cmd = new SqlCommand(commandText, conn);
  42 + cmd.CommandType = CommandType.StoredProcedure;
50 43 SqlDataAdapter da = new SqlDataAdapter();
51 44 da.SelectCommand = cmd;
52 45 ds = new DataSet();
... ... @@ -59,210 +52,204 @@ namespace AIAHTML5.API.Models
59 52 return ds;
60 53 }
61 54  
62   - public ArrayList GetUserModules()
  55 + internal ArrayList GetAllModules()
63 56 {
  57 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  58 + logger.Debug(" Inside GetAllModules");
  59 +
64 60 ArrayList arrUserModules = new ArrayList();
65   - Hashtable userModuleHash = null;
66   - userModuleHash = new Hashtable();
67 61  
68   - string sp = "GetAllModuleStatusWithSlug";
  62 + try
  63 + {
  64 + Hashtable userModuleHash = new Hashtable();
  65 +
  66 + string sp = DBConstants.GET_ALL_MODULES;
69 67  
70   - DataSet ds = DBModel.GetSQLData(sp, true);
71   - DataTable dt = ds.Tables[0];
  68 + DataSet ds = DBModel.GetDataFromStoredProcedure(sp);
72 69  
73   - foreach (DataRow drActType in dt.Rows)
  70 + if (ds.Tables.Count > 0)
  71 + {
  72 + DataTable dt = ds.Tables[0];
  73 +
  74 + foreach (DataRow drModule in dt.Rows)
  75 + {
  76 + userModuleHash = new Hashtable();
  77 + userModuleHash.Add(AIAConstants.KEY_NAME, drModule["Name"]);
  78 + userModuleHash.Add(AIAConstants.KEY_SLUG, drModule["Slug"]);
  79 + arrUserModules.Add(userModuleHash);
  80 + }
  81 + }
  82 + }
  83 + catch (SqlException ex)
74 84 {
75   - userModuleHash = new Hashtable();
76   - userModuleHash.Add(AIAConstants.KEY_NAME, drActType["Name"]);
77   - userModuleHash.Add(AIAConstants.KEY_SLUG, drActType["Slug"]);
78   - arrUserModules.Add(userModuleHash);
  85 + logger.Fatal("Exception in GetAllModules , Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
79 86 }
80 87 return arrUserModules;
81 88 }
82 89  
83   - public static dynamic GetUserDetailsByLoginIdAndPassword(string loginId, string password)
  90 + internal static dynamic GetUserDetailsByLoginId(string loginId)
84 91 {
  92 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  93 + logger.Debug(" Inside GetUserDetailsByLoginId for LoginId = " + loginId);
  94 +
85 95 User objUser = new User();
86 96 DBModel objModel = new DBModel();
87 97  
88   - conn = new SqlConnection(dbConnectionString);
89   - cmd = new SqlCommand();
90   - SqlDataAdapter da = new SqlDataAdapter();
91   - SqlParameter param;
92   - DataSet ds = new DataSet();
  98 + try
  99 + {
  100 + conn = new SqlConnection(dbConnectionString);
  101 + cmd = new SqlCommand();
  102 + SqlDataAdapter da = new SqlDataAdapter();
  103 + SqlParameter param;
  104 + DataSet ds = new DataSet();
93 105  
94   - cmd.Connection = conn;
95   - cmd.CommandText = "GetUserDetailsByLoginId";
96   - cmd.CommandType = CommandType.StoredProcedure;
  106 + cmd.Connection = conn;
  107 + cmd.CommandText = DBConstants.GET_USER_DELAILS_BY_LOGIN_ID;
  108 + cmd.CommandType = CommandType.StoredProcedure;
97 109  
98   - param = new SqlParameter("@sLoginId", loginId);
99   - param.Direction = ParameterDirection.Input;
100   - param.DbType = DbType.String;
101   - cmd.Parameters.Add(param);
  110 + param = new SqlParameter("@sLoginId", loginId);
  111 + param.Direction = ParameterDirection.Input;
  112 + param.DbType = DbType.String;
  113 + cmd.Parameters.Add(param);
102 114  
103   - da.SelectCommand = cmd;
104   - DataTable dt = new DataTable();
105   - da.Fill(dt);
  115 + da.SelectCommand = cmd;
  116 + DataTable dt = new DataTable();
  117 + da.Fill(dt);
106 118  
107   - if (dt.Rows.Count > 0)
108   - {
109   - foreach (DataRow dr in dt.Rows)
  119 + if (dt.Rows.Count > 0)
110 120 {
111   - foreach (DataColumn dc in dt.Columns)
  121 + foreach (DataRow dr in dt.Rows)
112 122 {
113   - if (dc.ColumnName == "Id")
114   - objUser.Id = Convert.ToInt32(dr[dc]);
115   - if (dc.ColumnName == "FirstName")
116   - objUser.FirstName = dr[dc].ToString();
117   - if (dc.ColumnName == "LastName")
118   - objUser.LastName = dr[dc].ToString();
119   - if (dc.ColumnName == "EmailId")
120   - objUser.EmailId = dr[dc].ToString();
121   - if (dc.ColumnName == "LoginId")
122   - objUser.LoginId = dr[dc].ToString();
123   - if (dc.ColumnName == "Password")
124   - objUser.Password = dr[dc].ToString();
125   - if (dc.ColumnName == "SecurityQuestionId")
126   - {
127   - int tempVal;
128   - objUser.SecurityQuestionId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null;
129   - }
130   - if (dc.ColumnName == "SecurityAnswer")
131   - objUser.SecurityAnswer = dr[dc].ToString();
132   - if (dc.ColumnName == "CreatorId")
133   - {
134   - int tempVal;
135   - objUser.CreatorId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null;
136   - }
137   - if (dc.ColumnName == "CreationDate")
138   - objUser.CreationDate = Convert.ToDateTime(dr[dc]);
139   - if (dc.ColumnName == "DeactivationDate")
140   - {
141   - DateTime? date;
142   - if (dr[dc] == DBNull.Value)
143   - date = null;
144   - else
145   - date = (DateTime)dr[dc];
146   -
147   - objUser.DeactivationDate = date;
148   - }
149   - if (dc.ColumnName == "ModifierId")
150   - {
151   - int tempVal;
152   - objUser.ModifierId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null;
153   - }
154   - if (dc.ColumnName == "ModifiedDate")
155   - {
156   - DateTime? date;
157   - if (dr[dc] == DBNull.Value)
158   - date = null;
159   - else
160   - date = (DateTime)dr[dc];
161   -
162   - objUser.ModifiedDate = date;
163   - }
164   - if (dc.ColumnName == "UserTypeId")
165   - {
166   - objUser.UserTypeId = Convert.ToInt32(dr[dc]);
167   - objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr[dc]));
168   - }
169   - if (dc.ColumnName == "IsActive")
170   - objUser.IsActive = Convert.ToBoolean(dr[dc]);
171   -
  123 + int tempVal;
  124 + DateTime date;
  125 +
  126 + objUser.Id = Convert.ToInt32(dr["Id"]);
  127 + objUser.FirstName = dr["FirstName"].ToString();
  128 + objUser.LastName = dr["LastName"].ToString();
  129 + objUser.EmailId = dr["EmailId"].ToString();
  130 + objUser.LoginId = dr["LoginId"].ToString();
  131 + objUser.Password = dr["Password"].ToString();
  132 + objUser.SecurityQuestionId =Int32.TryParse(dr["SecurityQuestionId"].ToString(), out tempVal) ? tempVal : (int?)null;
  133 + objUser.SecurityAnswer = dr["SecurityAnswer"].ToString(); ;
  134 + objUser.CreatorId = Int32.TryParse(dr["CreatorId"].ToString(), out tempVal) ? tempVal : (int?)null;
  135 + objUser.CreationDate = Convert.ToDateTime(dr["CreationDate"]);
  136 + objUser.DeactivationDate = DateTime.TryParse(dr["DeactivationDate"].ToString(), out date) ? date : (DateTime?)null;
  137 + objUser.ModifierId = Int32.TryParse(dr["ModifierId"].ToString(), out tempVal) ? tempVal : (int?)null;
  138 + objUser.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null;
  139 + objUser.UserTypeId = Convert.ToInt32(dr["UserTypeId"]);
  140 + objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr["UserTypeId"]));
  141 + objUser.IsActive = Convert.ToBoolean(dr["IsActive"]);
172 142 }
173 143 }
  144 + else
  145 + {
  146 + objUser = null;
  147 + }
174 148 }
175   - else
  149 + catch (SqlException ex)
176 150 {
177   - objUser = null;
  151 + logger.Fatal("Exception in GetUserDetailsByLoginId for LoginId: " + loginId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
178 152 }
179 153 return objUser;
180 154 }
181 155  
182   - public Hashtable GetUserLicenseDetailByUserId(int userId)
  156 + internal Hashtable GetLicenseDetailByUserId(int userId)
183 157 {
  158 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  159 + logger.Debug(" Inside GetUserLicenseDetailByUserId for UserId = " + userId);
  160 +
184 161 Hashtable hash = new Hashtable();
185 162  
186   - conn = new SqlConnection(dbConnectionString);
187   - cmd = new SqlCommand();
188   - SqlDataAdapter adapter;
189   - SqlParameter param;
190   - DataSet ds = new DataSet();
  163 + try
  164 + {
  165 + conn = new SqlConnection(dbConnectionString);
  166 + cmd = new SqlCommand();
  167 + SqlDataAdapter adapter;
  168 + SqlParameter param;
  169 + DataSet ds = new DataSet();
  170 +
  171 + cmd.Connection = conn;
  172 + cmd.CommandText = DBConstants.GET_LICENSE_DETAILS_BY_USER_ID;
  173 + cmd.CommandType = CommandType.StoredProcedure;
191 174  
192   - cmd.Connection = conn;
193   - cmd.CommandText = "GetLicenseDetailByUserId";
194   - cmd.CommandType = CommandType.StoredProcedure;
  175 + param = new SqlParameter("@iUserId", userId);
  176 + param.Direction = ParameterDirection.Input;
  177 + param.DbType = DbType.Int32;
  178 + cmd.Parameters.Add(param);
195 179  
196   - param = new SqlParameter("@iUserId", userId);
197   - param.Direction = ParameterDirection.Input;
198   - param.DbType = DbType.Int32;
199   - cmd.Parameters.Add(param);
  180 + adapter = new SqlDataAdapter(cmd);
  181 + adapter.Fill(ds);
200 182  
201   - adapter = new SqlDataAdapter(cmd);
202   - adapter.Fill(ds);
203   - if (ds.Tables[0].Rows.Count > 0)
  183 + if (ds.Tables.Count > 0)
  184 + {
  185 + if (ds.Tables[0].Rows.Count > 0)
  186 + {
  187 + hash.Add(AIAConstants.LICENSE_KEY_ID, ds.Tables[0].Rows[0][0]);
  188 + hash.Add(AIAConstants.EDITION_KEY_ID, ds.Tables[0].Rows[0][1]);
  189 + }
  190 + }
  191 + }
  192 + catch (SqlException ex)
204 193 {
205   - hash.Add("LicenseId", ds.Tables[0].Rows[0][0]);
206   - hash.Add("EditionId", ds.Tables[0].Rows[0][1]);
  194 + logger.Fatal("Exception in GetUserLicenseDetailByUserId for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
207 195 }
  196 +
208 197 return hash;
209 198 }
210 199  
211   - public ArrayList GetUserModulesByLicenseId(int licenseId)
  200 + internal ArrayList GetUserModulesByLicenseId(int licenseId)
212 201 {
213   - ArrayList userModulelist = new ArrayList();
214   - Hashtable modulesHash;
215   - DataSet ds = new DataSet();
  202 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  203 + logger.Debug(" Inside GetUserModulesByLicenseId for LicenseId = " + licenseId);
216 204  
217   - conn = new SqlConnection(dbConnectionString);
218   - cmd = new SqlCommand();
219   - SqlDataAdapter adapter;
220   - SqlParameter param;
  205 + ArrayList userModulelist = new ArrayList();
221 206  
222   - cmd.Connection = conn;
223   - cmd.CommandText = "GetUserModulesByLicenseId";
224   - cmd.CommandType = CommandType.StoredProcedure;
  207 + try
  208 + {
  209 + Hashtable modulesHash;
  210 + DataSet ds = new DataSet();
225 211  
226   - param = new SqlParameter("@iLicenseId", licenseId);
227   - param.Direction = ParameterDirection.Input;
228   - param.DbType = DbType.Int32;
229   - cmd.Parameters.Add(param);
  212 + conn = new SqlConnection(dbConnectionString);
  213 + cmd = new SqlCommand();
  214 + SqlDataAdapter adapter;
  215 + SqlParameter param;
230 216  
231   - adapter = new SqlDataAdapter(cmd);
232   - adapter.Fill(ds);
233   - DataTable dt = ds.Tables[0];
  217 + cmd.Connection = conn;
  218 + cmd.CommandText = DBConstants.GET_USER_MODULES_BY_LICENSE_ID;
  219 + cmd.CommandType = CommandType.StoredProcedure;
234 220  
235   - foreach (DataRow dr in dt.Rows)
236   - {
237   - modulesHash = new Hashtable();
238   - modulesHash.Add("name", dr["Title"]);
239   - modulesHash.Add("slug", dr["Slug"]);
240   - userModulelist.Add(modulesHash);
241   - }
  221 + param = new SqlParameter("@iLicenseId", licenseId);
  222 + param.Direction = ParameterDirection.Input;
  223 + param.DbType = DbType.Int32;
  224 + cmd.Parameters.Add(param);
242 225  
243   - return userModulelist;
244   - }
  226 + adapter = new SqlDataAdapter(cmd);
  227 + adapter.Fill(ds);
  228 +
245 229  
246   - public ArrayList GetUserModulesList(ArrayList allModules, ArrayList modulesByLicense)
247   - {
248   - ArrayList userModules = new ArrayList();
249   - Hashtable moduleHash;
250   - foreach (Hashtable module in allModules)
251   - {
252   - foreach (Hashtable userModule in modulesByLicense)
  230 + if (ds.Tables.Count > 0)
253 231 {
254   - if ((userModule["Title"].ToString().Trim() == module["name"].ToString().Trim()) && (Convert.ToBoolean(userModule["Status"]) == true))
255   - {
256   - moduleHash = new Hashtable();
257   - moduleHash.Add("name", userModule["Title"]);
258   - moduleHash.Add("slug", module["slug"]);
  232 + DataTable dt = ds.Tables[0];
259 233  
260   - userModules.Add(moduleHash);
  234 + if (dt.Rows.Count > 0)
  235 + {
  236 + foreach (DataRow dr in dt.Rows)
  237 + {
  238 + modulesHash = new Hashtable();
  239 + modulesHash.Add(AIAConstants.KEY_NAME, dr["Title"]);
  240 + modulesHash.Add(AIAConstants.KEY_SLUG, dr["Slug"]);
  241 + userModulelist.Add(modulesHash);
  242 + }
261 243 }
262 244 }
263 245 }
264 246  
265   - return userModules;
  247 + catch (SqlException ex)
  248 + {
  249 + logger.Fatal("Exception in GetUserModulesByLicenseId for LicenseId = " + licenseId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
  250 + }
  251 +
  252 + return userModulelist;
266 253 }
267 254  
268 255 protected string GetUserTypeStringById(int userTypeId)
... ... @@ -271,38 +258,38 @@ namespace AIAHTML5.API.Models
271 258  
272 259 switch (userTypeId)
273 260 {
274   - case 1:
  261 + case (int)UserType.SUPER_ADMIN:
275 262 userType = User.SUPER_ADMIN;
276 263 break;
277   - case 2:
  264 + case (int)UserType.GENERAL_ADMIN:
278 265 userType = User.GENERAL_ADMIN;
279 266 break;
280   - case 3:
  267 + case (int)UserType.DISTRICT_ADMIN:
281 268 userType = User.DISTRICT_ADMIN;
282 269 break;
283   - case 4:
  270 + case (int)UserType.CLIENT_ADMIN:
284 271 userType = User.CLIENT_ADMIN;
285 272 break;
286   - case 5:
  273 + case (int)UserType.SINGLE_USER:
287 274 userType = User.SINGLE_USER;
288 275 break;
289   - case 6:
  276 + case (int)UserType.CONCURRENT_USER:
290 277 userType = User.CONCURRENT_USER;
291 278 break;
292   - case 7:
  279 + case (int)UserType.RESELLER:
293 280 userType = User.RESELLER;
294 281 break;
295   - case 8:
  282 + case (int)UserType.TEST_ACCOUNT:
296 283 userType = User.TEST_ACCOUNT;
297 284 break;
298   - case 9:
  285 + case (int)UserType.SITE_USER:
299 286 userType = User.SITE_USER;
300 287 break;
301 288 }
302 289 return userType;
303 290 }
304 291  
305   - public static User GetUserDetailsByEmailId(string emailId)
  292 + internal static User GetUserDetailsByEmailId(string emailId)
306 293 {
307 294 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
308 295 logger.Debug(" Inside GetUserDetailsByEmailId for emailId = " + emailId);
... ... @@ -310,109 +297,105 @@ namespace AIAHTML5.API.Models
310 297 User objUser = new User();
311 298 DBModel objModel = new DBModel();
312 299  
313   - conn = new SqlConnection(dbConnectionString);
314   - cmd = new SqlCommand();
315   - SqlDataAdapter adapter;
316   - SqlParameter param;
317   - DataSet ds = new DataSet();
  300 + try
  301 + {
318 302  
319   - cmd.Connection = conn;
320   - cmd.CommandText = "GetUserInfoByEmailId";
321   - cmd.CommandType = CommandType.StoredProcedure;
  303 + conn = new SqlConnection(dbConnectionString);
  304 + cmd = new SqlCommand();
  305 + SqlDataAdapter adapter;
  306 + SqlParameter param;
  307 + DataSet ds = new DataSet();
322 308  
323   - param = new SqlParameter("@sEmailId", emailId);
324   - param.Direction = ParameterDirection.Input;
325   - param.DbType = DbType.String;
326   - cmd.Parameters.Add(param);
  309 + cmd.Connection = conn;
  310 + cmd.CommandText = DBConstants.GET_USER_DETAILS_BY_EMAILID;
  311 + cmd.CommandType = CommandType.StoredProcedure;
327 312  
328   - adapter = new SqlDataAdapter(cmd);
329   - adapter.Fill(ds);
330   - DataTable dt = ds.Tables[0];
  313 + param = new SqlParameter("@sEmailId", emailId);
  314 + param.Direction = ParameterDirection.Input;
  315 + param.DbType = DbType.String;
  316 + cmd.Parameters.Add(param);
331 317  
332   - foreach (DataRow dr in dt.Rows)
333   - {
334   - foreach (DataColumn dc in dt.Columns)
  318 + adapter = new SqlDataAdapter(cmd);
  319 + adapter.Fill(ds);
  320 +
  321 +
  322 + if (ds.Tables.Count > 0)
335 323 {
336   - if (dc.ColumnName == "Id")
337   - objUser.Id = Convert.ToInt32(dr[dc]);
338   - if (dc.ColumnName == "FirstName")
339   - objUser.FirstName = dr[dc].ToString();
340   - if (dc.ColumnName == "LastName")
341   - objUser.LastName = dr[dc].ToString();
342   - if (dc.ColumnName == "EmailId")
343   - objUser.EmailId = dr[dc].ToString();
344   - if (dc.ColumnName == "LoginId")
345   - objUser.LoginId = dr[dc].ToString();
346   - if (dc.ColumnName == "Password")
347   - objUser.Password = dr[dc].ToString();
348   - if (dc.ColumnName == "SecurityQuestionId")
349   - {
350   - int tempVal;
351   - objUser.SecurityQuestionId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null;
352   - }
353   - if (dc.ColumnName == "SecurityAnswer")
354   - objUser.SecurityAnswer = dr[dc].ToString();
355   - if (dc.ColumnName == "CreatorId")
356   - {
357   - int tempVal;
358   - objUser.CreatorId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null;
359   - }
360   - if (dc.ColumnName == "CreationDate")
361   - objUser.CreationDate = Convert.ToDateTime(dr[dc]);
362   - if (dc.ColumnName == "DeactivationDate")
363   - {
364   - DateTime? date;
365   - if (dr[dc] == DBNull.Value)
366   - date = null;
367   - else
368   - date = (DateTime)dr[dc];
  324 + DataTable dt = ds.Tables[0];
369 325  
370   - objUser.DeactivationDate = date;
371   - }
372   - if (dc.ColumnName == "ModifierId")
  326 + if (dt.Rows.Count > 0)
373 327 {
374   - int tempVal;
375   - objUser.ModifierId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null;
376   - }
377   - if (dc.ColumnName == "ModifiedDate")
378   - {
379   - DateTime? date;
380   - if (dr[dc] == DBNull.Value)
381   - date = null;
382   - else
383   - date = (DateTime)dr[dc];
384   -
385   - objUser.ModifiedDate = date;
  328 + foreach (DataRow dr in dt.Rows)
  329 + {
  330 + int tempVal;
  331 + DateTime date;
  332 +
  333 + objUser.Id = Convert.ToInt32(dr["Id"]);
  334 + objUser.FirstName = dr["FirstName"].ToString();
  335 + objUser.LastName = dr["LastName"].ToString();
  336 + objUser.EmailId = dr["EmailId"].ToString();
  337 + objUser.LoginId = dr["LoginId"].ToString();
  338 + objUser.Password = dr["Password"].ToString();
  339 + objUser.SecurityQuestionId = Int32.TryParse(dr["SecurityQuestionId"].ToString(), out tempVal) ? tempVal : (int?)null;
  340 + objUser.SecurityAnswer = dr["SecurityAnswer"].ToString(); ;
  341 + objUser.CreatorId = Int32.TryParse(dr["CreatorId"].ToString(), out tempVal) ? tempVal : (int?)null;
  342 + objUser.CreationDate = Convert.ToDateTime(dr["CreationDate"]);
  343 + objUser.DeactivationDate = DateTime.TryParse(dr["DeactivationDate"].ToString(), out date) ? date : (DateTime?)null;
  344 + objUser.ModifierId = Int32.TryParse(dr["ModifierId"].ToString(), out tempVal) ? tempVal : (int?)null;
  345 + objUser.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null;
  346 + objUser.UserTypeId = Convert.ToInt32(dr["UserTypeId"]);
  347 + objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr["UserTypeId"]));
  348 + objUser.IsActive = Convert.ToBoolean(dr["IsActive"]);
  349 + }
386 350 }
387   - if (dc.ColumnName == "UserTypeId")
388   - objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr[dc]));
389   - if (dc.ColumnName == "IsActive")
390   - objUser.IsActive = Convert.ToBoolean(dr[dc]);
391   -
392 351 }
  352 + else
  353 + {
  354 + objUser = null;
  355 + }
  356 + }
  357 + catch (SqlException ex)
  358 + {
  359 + logger.Fatal("Exception in GetUserDetailsByEmailId for emailId = " + emailId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
393 360 }
394 361  
395 362 return objUser;
396 363 }
397 364  
398   - public static int UpdateUserPassword(dynamic userInfo, string loginId, string emailId)
  365 + internal static int UpdateUserPassword(dynamic userInfo, string loginId, string emailId)
399 366 {
  367 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  368 + logger.Debug(" Inside UpdateUserPassword for LoginId: " + loginId + ", EmailId: " + emailId);
  369 +
400 370 int result = 0;
401   - conn = new SqlConnection(dbConnectionString);
402   - cmd = new SqlCommand();
403   - cmd.Connection = conn;
404   - conn.Open();
405   - cmd.CommandText = "UpdateUserPassword";
406   - cmd.CommandType = CommandType.StoredProcedure;
407   - cmd.Parameters.AddWithValue("@sLoginId", loginId);
408   - cmd.Parameters.AddWithValue("@sEmailId", emailId);
409   - cmd.Parameters.AddWithValue("@sNewPassword", userInfo["newPassword"].ToString());
410   - result = cmd.ExecuteNonQuery();
411   - conn.Close();
  371 +
  372 + try
  373 + {
  374 + conn = new SqlConnection(dbConnectionString);
  375 + cmd = new SqlCommand();
  376 + cmd.Connection = conn;
  377 + conn.Open();
  378 + cmd.CommandText = DBConstants.UPDATE_USER_PASSWORD;
  379 + cmd.CommandType = CommandType.StoredProcedure;
  380 + cmd.Parameters.AddWithValue("@sLoginId", loginId);
  381 + cmd.Parameters.AddWithValue("@sEmailId", emailId);
  382 + cmd.Parameters.AddWithValue("@sNewPassword", userInfo["newPassword"].ToString());
  383 + result = cmd.ExecuteNonQuery();
  384 + conn.Close();
  385 + }
  386 + catch (SqlException ex)
  387 + {
  388 + conn.Close();
  389 + logger.Fatal("Exception in UpdateUserPassword for LoginId: " + loginId + ", EmailId: " + emailId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
  390 + }
  391 + finally
  392 + {
  393 + conn.Dispose();
  394 + }
412 395 return result;
413 396 }
414 397  
415   - public LicenseSubscriptionDetails GetLicenseSubscriptionDetailsByLicenseId(int licenseId)
  398 + internal LicenseSubscriptionDetails GetLicenseSubscriptionDetailsByLicenseId(int licenseId)
416 399 {
417 400 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
418 401 logger.Debug(" Inside GetLicenseSubscriptionDetailsByLicenseId for LicenseId = " + licenseId);
... ... @@ -427,7 +410,7 @@ namespace AIAHTML5.API.Models
427 410 DataSet ds = new DataSet();
428 411  
429 412 cmd.Connection = conn;
430   - cmd.CommandText = "GetSubscriptionDetailsByLicenseId";
  413 + cmd.CommandText = DBConstants.GET_SUBSCRIPTION_DETAILS_BY_LICENSE_ID;
431 414 cmd.CommandType = CommandType.StoredProcedure;
432 415  
433 416 param = new SqlParameter("@iLicenseId", licenseId);
... ... @@ -436,64 +419,37 @@ namespace AIAHTML5.API.Models
436 419 cmd.Parameters.Add(param);
437 420  
438 421 adapter = new SqlDataAdapter(cmd);
439   - adapter.Fill(ds);
440   - DataTable dt = ds.Tables[0];
  422 + adapter.Fill(ds);
441 423  
442   - foreach (DataRow dr in dt.Rows)
  424 + if (ds.Tables.Count > 0)
443 425 {
444   - foreach (DataColumn dc in dt.Columns)
  426 + DataTable dt = ds.Tables[0];
  427 +
  428 + if (dt.Rows.Count > 0)
445 429 {
446   - if (dc.ColumnName == "Id")
447   - lsd.Id = Convert.ToInt32(dr[dc]);
448   - if (dc.ColumnName == "LicenseId")
449   - lsd.LicenseId = Convert.ToInt32(dr[dc]);
450   - if (dc.ColumnName == "SubscriptionPlanId")
  430 + foreach (DataRow dr in dt.Rows)
451 431 {
452 432 int tempVal;
453   - lsd.SubscriptionPlanId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null;
  433 + DateTime date;
  434 + lsd.Id = Convert.ToInt32(dr["Id"]);
  435 + lsd.LicenseId = Convert.ToInt32(dr["LicenseId"]);
  436 + lsd.SubscriptionPlanId = Int32.TryParse(dr["SubscriptionPlanId"].ToString(), out tempVal) ? tempVal : (int?)null;
  437 + lsd.SubscriptionValidFrom = DateTime.TryParse(dr["SubscriptionValidFrom"].ToString(), out date) ? date : (DateTime?)null;
  438 + lsd.SubscriptionValidThrough = DateTime.TryParse(dr["SubscriptionValidThrough"].ToString(), out date) ? date : (DateTime?)null;
  439 + lsd.RenewalDate = DateTime.TryParse(dr["RenewalDate"].ToString(), out date) ? date : (DateTime?)null;
  440 + lsd.PaymentMode = dr["PaymentMode"].ToString();
  441 + lsd.TotalAmount = Convert.ToDouble(dr["TotalAmount"]);
  442 + lsd.AmountPaid = Convert.ToDouble(dr["AmountPaid"]);
  443 + lsd.AmountPending = Convert.ToDouble(dr["AmountPending"]);
  444 + lsd.NoOfImages = Convert.ToInt32(dr["NoofImages"]);
454 445 }
455   - if (dc.ColumnName == "SubscriptionValidFrom")
456   - {
457   - DateTime? date;
458   - if (dr[dc] == DBNull.Value)
459   - date = null;
460   - else
461   - date = (DateTime)dr[dc];
462   -
463   - lsd.SubscriptionValidFrom = date;
464   - }
465   - if (dc.ColumnName == "SubscriptionValidThrough")
466   - {
467   - DateTime? date;
468   - if (dr[dc] == DBNull.Value)
469   - date = null;
470   - else
471   - date = (DateTime)dr[dc];
472   -
473   - lsd.SubscriptionValidThrough = date;
474   - }
475   - if (dc.ColumnName == "RenewelDate")
476   - {
477   - DateTime? date;
478   - if (dr[dc] == DBNull.Value)
479   - date = null;
480   - else
481   - date = (DateTime)dr[dc];
482   -
483   - lsd.RenewalDate = date;
484   - }
485   - if (dc.ColumnName == "PaymentMode")
486   - lsd.PaymentMode = dr[dc].ToString();
487   - if (dc.ColumnName == "TotalAmount")
488   - lsd.TotalAmount = Convert.ToDouble(dr[dc]);
489   - if (dc.ColumnName == "AmountPaid")
490   - lsd.AmountPaid = Convert.ToDouble(dr[dc]);
491   - if (dc.ColumnName == "AmountPending")
492   - lsd.AmountPending = Convert.ToDouble(dr[dc]);
493   - if (dc.ColumnName == "NoofImages")
494   - lsd.NoOfImages = Convert.ToInt32(dr[dc]);
495 446 }
496 447 }
  448 + else
  449 + {
  450 + lsd = null;
  451 + }
  452 +
497 453 }
498 454 catch (Exception ex)
499 455 {
... ... @@ -503,12 +459,12 @@ namespace AIAHTML5.API.Models
503 459 return lsd;
504 460 }
505 461  
506   - public License GetLicenseDetailsByLicenseId(int licenseId)
  462 + internal License GetLicenseDetailsByLicenseId(int licenseId)
507 463 {
508 464 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
509 465 logger.Debug(" inside GetLicenseDetailsByLicenseId for LicenseId = " + licenseId);
510 466  
511   - License lic = new License();
  467 + License license = new License();
512 468 try
513 469 {
514 470 conn = new SqlConnection(dbConnectionString);
... ... @@ -518,7 +474,7 @@ namespace AIAHTML5.API.Models
518 474 DataSet ds = new DataSet();
519 475  
520 476 cmd.Connection = conn;
521   - cmd.CommandText = "GetLicenseDetailsById";
  477 + cmd.CommandText = DBConstants.GET_LICENSE_DETAILS_BY_ID;
522 478 cmd.CommandType = CommandType.StoredProcedure;
523 479  
524 480 param = new SqlParameter("@Id", licenseId);
... ... @@ -528,110 +484,114 @@ namespace AIAHTML5.API.Models
528 484  
529 485 adapter = new SqlDataAdapter(cmd);
530 486 adapter.Fill(ds);
531   - DataTable dt = ds.Tables[0];
532 487  
533   - foreach (DataRow dr in dt.Rows)
  488 + if (ds.Tables.Count > 0)
534 489 {
535   - foreach (DataColumn dc in dt.Columns)
  490 + DataTable dt = ds.Tables[0];
  491 + if (dt.Rows.Count > 0)
536 492 {
537   - if (dc.ColumnName == "Id")
538   - lic.Id = Convert.ToInt32(dr[dc]);
539   - if (dc.ColumnName == "AccountNumber")
540   - lic.AccountNumber = dr[dc].ToString();
541   - if (dc.ColumnName == "LicenseeFirstName")
542   - lic.LicenseeFirstName = dr[dc].ToString();
543   - if (dc.ColumnName == "LicenseeLastName")
544   - lic.LicenseeLastName = dr[dc].ToString();
545   - if (dc.ColumnName == "LicenseTypeId")
546   - lic.LicenseTypeId = Convert.ToInt32(dr[dc]);
547   - if (dc.ColumnName == "InstitutionName")
548   - lic.InstitutionName = dr[dc].ToString();
549   - if (dc.ColumnName == "Address1")
550   - lic.Address1 = dr[dc].ToString();
551   - if (dc.ColumnName == "Address2")
552   - lic.Address2 = dr[dc].ToString();
553   - if (dc.ColumnName == "CountryId")
554   - lic.CountryId = Convert.ToInt32(dr[dc]);
555   - if (dc.ColumnName == "StateId")
556   - lic.StateId = Convert.ToInt32(dr[dc]);
557   - if (dc.ColumnName == "City")
558   - lic.City = dr[dc].ToString();
559   - if (dc.ColumnName == "Zip")
560   - lic.Zip = dr[dc].ToString();
561   - if (dc.ColumnName == "Phone")
562   - lic.Phone = dr[dc].ToString();
563   - if (dc.ColumnName == "EmailId")
564   - lic.EmailId = dr[dc].ToString();
565   - if (dc.ColumnName == "TotalLogins")
566   - lic.TotalLogins = Convert.ToInt32(dr[dc]);
567   - if (dc.ColumnName == "AccountTypeId")
568   - lic.AccountTypeId = Convert.ToInt32(dr[dc]);
569   - if (dc.ColumnName == "IsActive")
570   - lic.IsActive = Convert.ToBoolean(dr[dc]);
571   - if (dc.ColumnName == "IsDistrictSiteLicense")
572   - lic.IsDistrictSiteLicense = Convert.ToBoolean(dr[dc]);
573   - if (dc.ColumnName == "CreationDate")
574   - lic.CreationDate = Convert.ToDateTime(dr[dc]);
575   - if (dc.ColumnName == "ModifiedDate")
  493 + foreach (DataRow dr in dt.Rows)
576 494 {
577   - DateTime? date;
578   - if (dr[dc] == DBNull.Value)
579   - date = null;
580   - else
581   - date = (DateTime)dr[dc];
582   -
583   - lic.ModifiedDate = date;
  495 + DateTime date;
  496 + license.Id = Convert.ToInt32(dr["Id"]);
  497 + license.AccountNumber = dr["AccountNumber"].ToString();
  498 + license.LicenseeFirstName = dr["LicenseeFirstName"].ToString();
  499 + license.LicenseeLastName = dr["LicenseeLastName"].ToString();
  500 + license.LicenseTypeId = Convert.ToInt32(dr["LicenseTypeId"]);
  501 + license.InstitutionName = dr["InstitutionName"].ToString();
  502 + license.Address1 = dr["Address1"].ToString();
  503 + license.Address2 = dr["Address2"].ToString();
  504 + license.CountryId = Convert.ToInt32(dr["CountryId"]);
  505 + license.StateId = Convert.ToInt32(dr["StateId"]);
  506 + license.City = dr["City"].ToString();
  507 + license.Zip = dr["Zip"].ToString();
  508 + license.Phone = dr["Phone"].ToString();
  509 + license.EmailId = dr["EmailId"].ToString();
  510 + license.TotalLogins = Convert.ToInt32(dr["TotalLogins"]);
  511 + license.AccountTypeId = Convert.ToInt32(dr["AccountTypeId"]);
  512 + license.IsActive = Convert.ToBoolean(dr["IsActive"]);
  513 + license.IsDistrictSiteLicense = Convert.ToBoolean(dr["IsDistrictSiteLicense"]);
  514 + license.CreationDate = Convert.ToDateTime(dr["CreationDate"]);
  515 + license.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null;
  516 + license.NoOfRenewals = Convert.ToInt32(dr["NoOfRenewals"]);
  517 + license.IsTermAccepted = Convert.ToBoolean(dr["IsTermsAccepted"]);
  518 + license.ProductId = dr["ProductId"].ToString();
584 519 }
585   - if (dc.ColumnName == "NoOfRenewals")
586   - lic.NoOfRenewals = Convert.ToInt32(dr[dc]);
587   - if (dc.ColumnName == "IsTermsAccepted")
588   - lic.IsTermAccepted = Convert.ToBoolean(dr[dc]);
589   - if (dc.ColumnName == "ProductId")
590   - lic.ProductId = dr[dc].ToString();
591 520 }
592 521 }
  522 + else
  523 + {
  524 + license = null;
  525 + }
593 526 }
594 527 catch (Exception ex)
595 528 {
596 529 logger.Fatal("Exception in GetLicenseDetailsByLicenseId for LicenseId= " + licenseId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
597 530 }
598 531  
599   - return lic;
  532 + return license;
600 533 }
601 534  
602   - public static int UpdateLicenseTermStatus(string accountNumber)
  535 + internal static int UpdateLicenseTermStatus(string accountNumber)
603 536 {
604 537 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
605 538 logger.Debug(" inside UpdateLicenseTermStatus for AccountNumber = " + accountNumber);
  539 +
606 540 int result = 0;
607   - conn = new SqlConnection(dbConnectionString);
608   - cmd = new SqlCommand();
609   - cmd.Connection = conn;
610   - conn.Open();
611   - cmd.CommandText = "UpdateLicenseTermAcceptedStatus";
612   - cmd.CommandType = CommandType.StoredProcedure;
613   - cmd.Parameters.AddWithValue("@sAccountNumber", accountNumber);
614   - result = cmd.ExecuteNonQuery();
615   - conn.Close();
  541 +
  542 + try
  543 + {
  544 + conn = new SqlConnection(dbConnectionString);
  545 + cmd = new SqlCommand();
  546 + cmd.Connection = conn;
  547 + conn.Open();
  548 + cmd.CommandText = DBConstants.UPDATE_LICENSE_TERM_STATUS;
  549 + cmd.CommandType = CommandType.StoredProcedure;
  550 + cmd.Parameters.AddWithValue("@sAccountNumber", accountNumber);
  551 + result = cmd.ExecuteNonQuery();
  552 + conn.Close();
  553 + }
  554 + catch (SqlException ex)
  555 + {
  556 + logger.Fatal("Exception in UpdateLicenseTermStatus for AccountNumber =" + accountNumber + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
  557 + }
616 558 return result;
617 559 }
618 560  
619 561 internal static ArrayList GetTermsOfServiceText()
620 562 {
  563 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  564 + logger.Debug(" inside GetTermsOfServiceText");
  565 +
621 566 ArrayList arrTermsOfService = new ArrayList();
622   - Hashtable contentHash = null;
623   - string str = string.Empty;
624   - string spName = "GetTermsOfServiceText";
625   - DataSet ds = DBModel.GetSQLData(spName, true);
626   - DataTable dt = ds.Tables[0];
627 567  
628   - foreach (DataRow dr in dt.Rows)
  568 + try
629 569 {
630   - contentHash = new Hashtable();
631   - contentHash.Add(AIAConstants.KEY_TITLE, dr["Title"]);
632   - contentHash.Add(AIAConstants.KEY_CONTENT, dr["Content"]);
633   - arrTermsOfService.Add(contentHash);
  570 + Hashtable contentHash = null;
  571 + string str = string.Empty;
  572 + string spName = DBConstants.GET_TERMS_OF_SERVICE_TEXT;
  573 + DataSet ds = DBModel.GetDataFromStoredProcedure(spName);
  574 +
  575 + if (ds.Tables.Count > 0)
  576 + {
  577 + DataTable dt = ds.Tables[0];
  578 + if (dt.Rows.Count > 0)
  579 + {
  580 + foreach (DataRow dr in dt.Rows)
  581 + {
  582 + contentHash = new Hashtable();
  583 + contentHash.Add(AIAConstants.KEY_TITLE, dr["Title"]);
  584 + contentHash.Add(AIAConstants.KEY_CONTENT, dr["Content"]);
  585 + arrTermsOfService.Add(contentHash);
  586 + }
  587 + }
  588 + }
  589 + }
  590 + catch (SqlException ex)
  591 + {
  592 + logger.Fatal("Exception in GetTermsOfServiceText, Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
634 593 }
  594 +
635 595 return arrTermsOfService;
636 596 }
637 597  
... ... @@ -647,7 +607,7 @@ namespace AIAHTML5.API.Models
647 607 cmd = new SqlCommand();
648 608 cmd.Connection = conn;
649 609 conn.Open();
650   - cmd.CommandText = "InsertLoginDetail";
  610 + cmd.CommandText = DBConstants.INSERT_LOGIN_DETAIL;
651 611 cmd.CommandType = CommandType.StoredProcedure;
652 612 cmd.Parameters.AddWithValue("@iUserId", userId);
653 613 result = cmd.ExecuteNonQuery();
... ... @@ -658,10 +618,15 @@ namespace AIAHTML5.API.Models
658 618 conn.Close();
659 619 logger.Fatal("Exception in InsertLoginDetails for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE=" + ex.StackTrace);
660 620 }
  621 + finally
  622 + {
  623 + conn.Dispose();
  624 + }
  625 +
661 626 return result;
662 627 }
663 628  
664   - public int InsertIncorrectLoginAttempts(int userId)
  629 + internal int InsertIncorrectLoginAttempts(int userId)
665 630 {
666 631 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
667 632 logger.Debug(" inside InsertIncorrectLoginAttempts for UserId= " + userId);
... ... @@ -673,7 +638,7 @@ namespace AIAHTML5.API.Models
673 638 cmd = new SqlCommand();
674 639 cmd.Connection = conn;
675 640 conn.Open();
676   - cmd.CommandText = "InsertIncorrectLoginAttempt";
  641 + cmd.CommandText = DBConstants.INSERT_INCORRECT_LOGIN_ATTEMPTS;
677 642 cmd.CommandType = CommandType.StoredProcedure;
678 643 cmd.Parameters.AddWithValue("@iUserId", userId);
679 644 result = cmd.ExecuteNonQuery();
... ... @@ -681,35 +646,48 @@ namespace AIAHTML5.API.Models
681 646 }
682 647 catch (SqlException ex)
683 648 {
  649 + conn.Close();
684 650 logger.Fatal("Exception in InsertIncorrectLoginAttempts for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
685 651 }
  652 + finally
  653 + {
  654 + conn.Dispose();
  655 + }
686 656 return result;
687 657 }
688 658  
689   - public int GetIncorrectLoginAttempts(int userId)
  659 + internal int GetIncorrectLoginAttempts(int userId)
690 660 {
691 661 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
692 662 logger.Debug(" inside GetIncorrectLoginAttempts for UserId = " + userId);
  663 +
693 664 int count = 0;
694 665 try
695 666 {
696 667 conn = new SqlConnection(dbConnectionString);
697 668 cmd = new SqlCommand();
698 669 cmd.Connection = conn;
699   - cmd.CommandText = "GetIncorrectLoginAttempt";
  670 + cmd.CommandText = DBConstants.GET_INCORRECT_LOGIN_ATTEMPTS;
700 671 cmd.CommandType = CommandType.StoredProcedure;
701 672 cmd.Parameters.AddWithValue("@iUserId", userId);
702 673 SqlDataAdapter da = new SqlDataAdapter();
703 674 da.SelectCommand = cmd;
704 675 DataSet ds = new DataSet();
705 676 da.Fill(ds);
706   - DataTable dt = ds.Tables[0];
707 677  
708   - foreach (DataRow dr in dt.Rows)
  678 + if (ds.Tables.Count > 0)
709 679 {
710   - foreach (DataColumn dc in dt.Columns)
  680 + DataTable dt = ds.Tables[0];
  681 +
  682 + if (dt.Rows.Count > 0)
711 683 {
712   - count = Convert.ToInt32(dr[dc]);
  684 + foreach (DataRow dr in dt.Rows)
  685 + {
  686 + foreach (DataColumn dc in dt.Columns)
  687 + {
  688 + count = Convert.ToInt32(dr[dc]);
  689 + }
  690 + }
713 691 }
714 692 }
715 693 }
... ... @@ -732,7 +710,7 @@ namespace AIAHTML5.API.Models
732 710 cmd = new SqlCommand();
733 711 cmd.Connection = conn;
734 712 conn.Open();
735   - cmd.CommandText = "UpdateIncorrectLoginAttempts";
  713 + cmd.CommandText = DBConstants.UPDATE_INCORRECT_LOGIN_ATTEMPTS;
736 714 cmd.CommandType = CommandType.StoredProcedure;
737 715 cmd.Parameters.AddWithValue("@iUserId", userId);
738 716 result = cmd.ExecuteNonQuery();
... ... @@ -743,6 +721,10 @@ namespace AIAHTML5.API.Models
743 721 conn.Close();
744 722 logger.Fatal("Exception in UpdateIncorrectLoginAttempts for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE=" + ex.StackTrace);
745 723 }
  724 + finally
  725 + {
  726 + conn.Dispose();
  727 + }
746 728 return result;
747 729 }
748 730  
... ... @@ -758,7 +740,7 @@ namespace AIAHTML5.API.Models
758 740 cmd = new SqlCommand();
759 741 cmd.Connection = conn;
760 742 conn.Open();
761   - cmd.CommandText = "DeleteIncorrectLoginAttempts";
  743 + cmd.CommandText = DBConstants.DELETE_INCORRECT_LOGIN_ATTEMPTS;
762 744 cmd.CommandType = CommandType.StoredProcedure;
763 745 cmd.Parameters.AddWithValue("@iUserId", userId);
764 746 result = cmd.ExecuteNonQuery();
... ... @@ -769,25 +751,47 @@ namespace AIAHTML5.API.Models
769 751 conn.Close();
770 752 logger.Fatal("Exception in DeleteIncorrectLoginAttempts for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
771 753 }
  754 + finally
  755 + {
  756 + conn.Dispose();
  757 + }
772 758 return result;
773 759 }
774 760  
775 761 protected ArrayList GetLoginFailureCauses()
776 762 {
  763 + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
  764 + logger.Debug(" Inside GetLoginFailureCauses");
  765 +
777 766 ArrayList failureCauseList = new ArrayList();
778   - Hashtable fcHash = null;
779 767  
780   - string sp = "GetAllLoginFailureCauses";
  768 + try
  769 + {
  770 + Hashtable fcHash = null;
  771 +
  772 + string sp = DBConstants.GET_ALL_LOGIN_FAILURE_CAUSES;
781 773  
782   - DataSet ds = DBModel.GetSQLData(sp, true);
783   - DataTable dt = ds.Tables[0];
  774 + DataSet ds = DBModel.GetDataFromStoredProcedure(sp);
  775 +
  776 + if (ds.Tables.Count > 0)
  777 + {
  778 + DataTable dt = ds.Tables[0];
784 779  
785   - foreach (DataRow drFailureCause in dt.Rows)
  780 + if (dt.Rows.Count > 0)
  781 + {
  782 + foreach (DataRow drFailureCause in dt.Rows)
  783 + {
  784 + fcHash = new Hashtable();
  785 + fcHash.Add(AIAConstants.KEY_ID, drFailureCause["Id"]);
  786 + fcHash.Add(AIAConstants.KEY_DESCRIPTION, drFailureCause["Description"]);
  787 + failureCauseList.Add(fcHash);
  788 + }
  789 + }
  790 + }
  791 + }
  792 + catch (SqlException ex)
786 793 {
787   - fcHash = new Hashtable();
788   - fcHash.Add(AIAConstants.KEY_ID, drFailureCause["Id"]);
789   - fcHash.Add(AIAConstants.KEY_DESCRIPTION, drFailureCause["Description"]);
790   - failureCauseList.Add(fcHash);
  794 + logger.Fatal("Exception in GetLoginFailureCauses, Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
791 795 }
792 796 return failureCauseList;
793 797 }
... ... @@ -804,7 +808,7 @@ namespace AIAHTML5.API.Models
804 808 cmd = new SqlCommand();
805 809 cmd.Connection = conn;
806 810 conn.Open();
807   - cmd.CommandText = "InsertLoginErrorLog";
  811 + cmd.CommandText = DBConstants.INSERT_LOGIN_ERROR_LOG;
808 812 cmd.CommandType = CommandType.StoredProcedure;
809 813 cmd.Parameters.AddWithValue("@nvAccountNumber", accountNumber);
810 814 cmd.Parameters.AddWithValue("@dtLogDate", DateTime.Now);
... ... @@ -817,12 +821,17 @@ namespace AIAHTML5.API.Models
817 821 }
818 822 catch (SqlException ex)
819 823 {
  824 + conn.Close();
820 825 logger.Fatal("Exception in InsertUserLoginLog for AccountNumber= " + accountNumber + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
821 826 }
  827 + finally
  828 + {
  829 + conn.Dispose();
  830 + }
822 831 return result;
823 832 }
824 833  
825   - protected BlockedUser GetBlockedUserByUserId(int userId)
  834 + internal BlockedUser GetBlockedUserByUserId(int userId)
826 835 {
827 836 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
828 837 logger.Debug(" inside GetBlockedUserByUserId for UserId= " + userId);
... ... @@ -834,7 +843,7 @@ namespace AIAHTML5.API.Models
834 843 conn = new SqlConnection(dbConnectionString);
835 844 cmd = new SqlCommand();
836 845 cmd.Connection = conn;
837   - cmd.CommandText = "GetBlockedUserByUserId";
  846 + cmd.CommandText = DBConstants.GET_BLOCKED_USER_BY_USER_ID;
838 847 cmd.CommandType = CommandType.StoredProcedure;
839 848 cmd.Parameters.AddWithValue("@userId", userId);
840 849 SqlDataAdapter da = new SqlDataAdapter();
... ... @@ -846,25 +855,14 @@ namespace AIAHTML5.API.Models
846 855 {
847 856 foreach (DataRow dr in dt.Rows)
848 857 {
849   - foreach (DataColumn dc in dt.Columns)
850   - {
851   - if (dc.ColumnName == "Id")
852   - blockedUser.Id = Convert.ToInt32(dr[dc]);
853   - if (dc.ColumnName == "FirstName")
854   - blockedUser.FirstName = dr[dc].ToString();
855   - if (dc.ColumnName == "LastName")
856   - blockedUser.LastName = dr[dc].ToString();
857   - if (dc.ColumnName == "EmailId")
858   - blockedUser.EmailId = dr[dc].ToString();
859   - if (dc.ColumnName == "LoginId")
860   - blockedUser.LoginId = dr[dc].ToString();
861   - if (dc.ColumnName == "Password")
862   - blockedUser.Password = dr[dc].ToString();
863   - if (dc.ColumnName == "AccountNumber")
864   - blockedUser.AccountNumber = dr[dc].ToString();
865   - if (dc.ColumnName == "LoginTime")
866   - blockedUser.LoginTime = Convert.ToDateTime(dr[dc]);
867   - }
  858 + blockedUser.Id = Convert.ToInt32(dr["Id"]);
  859 + blockedUser.FirstName = dr["FirstName"].ToString();
  860 + blockedUser.LastName = dr["LastName"].ToString();
  861 + blockedUser.EmailId = dr["EmailId"].ToString();
  862 + blockedUser.LoginId = dr["LoginId"].ToString();
  863 + blockedUser.Password = dr["Password"].ToString();
  864 + blockedUser.AccountNumber = dr["AccountNumber"].ToString();
  865 + blockedUser.LoginTime = Convert.ToDateTime(dr["LoginTime"]);
868 866 }
869 867 }
870 868 else
... ... @@ -879,7 +877,7 @@ namespace AIAHTML5.API.Models
879 877 return blockedUser;
880 878 }
881 879  
882   - protected ArrayList GetBlockedAdminUsers(int userTypeId)
  880 + protected ArrayList GetBlockedUsersByUserType(int userTypeId)
883 881 {
884 882 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
885 883 logger.Debug(" inside GetBlockedAdminUsers for UserTypeId= " + userTypeId);
... ... @@ -892,7 +890,7 @@ namespace AIAHTML5.API.Models
892 890 conn = new SqlConnection(dbConnectionString);
893 891 cmd = new SqlCommand();
894 892 cmd.Connection = conn;
895   - cmd.CommandText = "GetBlockedUserByUserType";
  893 + cmd.CommandText = DBConstants.GET_BLOCKED_USERS_BY_USER_TYPE;
896 894 cmd.CommandType = CommandType.StoredProcedure;
897 895 cmd.Parameters.AddWithValue("@iUserTypeId", userTypeId);
898 896 SqlDataAdapter da = new SqlDataAdapter();
... ... @@ -905,28 +903,23 @@ namespace AIAHTML5.API.Models
905 903 foreach (DataRow dr in dt.Rows)
906 904 {
907 905 blockedUser = new BlockedUser();
908   - foreach (DataColumn dc in dt.Columns)
909   - {
910   - if (dc.ColumnName == "Id")
911   - blockedUser.Id = Convert.ToInt32(dr[dc]);
912   - if (dc.ColumnName == "FirstName")
913   - blockedUser.FirstName = dr[dc].ToString();
914   - if (dc.ColumnName == "LastName")
915   - blockedUser.LastName = dr[dc].ToString();
916   - if (dc.ColumnName == "EmailId")
917   - blockedUser.EmailId = dr[dc].ToString();
918   - if (dc.ColumnName == "LoginId")
919   - blockedUser.LoginId = dr[dc].ToString();
920   - if (dc.ColumnName == "Password")
921   - blockedUser.Password = dr[dc].ToString();
922   - if (dc.ColumnName == "AccountNumber")
923   - blockedUser.AccountNumber = dr[dc].ToString();
924   - if (dc.ColumnName == "LoginTime")
925   - blockedUser.LoginTime = Convert.ToDateTime(dr[dc]);
926   - }
  906 +
  907 + blockedUser.Id = Convert.ToInt32(dr["Id"]);
  908 + blockedUser.FirstName = dr["FirstName"].ToString();
  909 + blockedUser.LastName = dr["LastName"].ToString();
  910 + blockedUser.EmailId = dr["EmailId"].ToString();
  911 + blockedUser.LoginId = dr["LoginId"].ToString();
  912 + blockedUser.Password = dr["Password"].ToString();
  913 + blockedUser.AccountNumber = dr["AccountNumber"].ToString();
  914 + blockedUser.LoginTime = Convert.ToDateTime(dr["LoginTime"]);
  915 +
927 916 blockedUsersList.Add(blockedUser);
928 917 }
929 918 }
  919 + else
  920 + {
  921 + blockedUser = null;
  922 + }
930 923 }
931 924 catch (SqlException ex)
932 925 {
... ... @@ -935,7 +928,7 @@ namespace AIAHTML5.API.Models
935 928 return blockedUsersList;
936 929 }
937 930  
938   - public static int UnblockUser(int userId)
  931 + internal static int UnblockUser(int userId)
939 932 {
940 933 int result = 0;
941 934 DBModel objModel = new DBModel();
... ... @@ -945,52 +938,27 @@ namespace AIAHTML5.API.Models
945 938 return result;
946 939 }
947 940  
948   - internal static bool ValidateUserAuthenticity(string username, string password)
  941 + internal static bool ValidateUserAuthenticity(string username, string password, User user)
949 942 {
950 943 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
951 944 logger.Debug(" Inside ValidateUserAuthenticity for Username = " + username + ", Password: " + password);
952 945  
953   - User objUser = new User();
954   - DBModel objModel = new DBModel();
955   -
956   - conn = new SqlConnection(dbConnectionString);
957   - cmd = new SqlCommand();
958   - SqlDataAdapter da = new SqlDataAdapter();
959   - SqlParameter param;
960   - DataSet ds = new DataSet();
961   -
962   - cmd.Connection = conn;
963   - cmd.CommandText = "GetUserDetailsByLoginId";
964   - cmd.CommandType = CommandType.StoredProcedure;
965   -
966   - param = new SqlParameter("@sLoginId", username);
967   - param.Direction = ParameterDirection.Input;
968   - param.DbType = DbType.String;
969   - cmd.Parameters.Add(param);
970   -
971   - da.SelectCommand = cmd;
972   - DataTable dt = new DataTable();
973   - da.Fill(dt);
974   -
975 946 bool result = false;
976 947  
977   - if (dt.Rows.Count > 0)
  948 + try
978 949 {
979   - foreach (DataRow dr in dt.Rows)
  950 + if ((string.Equals(username.ToUpper(), user.LoginId.ToUpper())) && (string.Equals(password, user.Password)))
980 951 {
981   - foreach (DataColumn dc in dt.Columns)
982   - {
983   - if (dc.ColumnName == "LoginId")
984   - objUser.LoginId = dr[dc].ToString();
985   - if (dc.ColumnName == "Password")
986   - objUser.Password = dr[dc].ToString();
987   - }
988   - }
989   -
990   - if ((string.Equals(username.ToUpper(), objUser.LoginId.ToUpper())) && (string.Equals(password, objUser.Password)))
991 952 result = true;
  953 + }
992 954 else
  955 + {
993 956 result = false;
  957 + }
  958 + }
  959 + catch (SqlException ex)
  960 + {
  961 + logger.Fatal("Exception in ValidateUserAuthenticity for Username = " + username + ", Password: " + password + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
994 962 }
995 963  
996 964 return result;
... ...