diff --git a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs index 1219f29..96df1b4 100644 --- a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs +++ b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Web; @@ -16,35 +16,26 @@ namespace AIAHTML5.API.Models { static string dbConnectionString = System.Configuration.ConfigurationManager.AppSettings["AIADatabaseV5Context"]; - static SqlConnection conn; - static SqlCommand cmd; private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); public DBModel() { } - public static void OpenConnection() - { - SqlConnection conn = new SqlConnection(dbConnectionString); - - if (conn.State == ConnectionState.Closed) - conn.Open(); - } protected static DataSet GetDataFromStoredProcedure(string commandText) { logger.Debug(" Inside GetSQLData for command text = " + commandText); DataSet ds = null; - SqlConnection conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(commandText, conn); - cmd.CommandType = CommandType.StoredProcedure; - SqlDataAdapter da = new SqlDataAdapter(); - da.SelectCommand = cmd; - ds = new DataSet(); - da.Fill(ds); - + SqlConnection conn = new SqlConnection(dbConnectionString); + SqlCommand cmd = new SqlCommand(commandText, conn); + cmd.CommandType = CommandType.StoredProcedure; + SqlDataAdapter da = new SqlDataAdapter(); + da.SelectCommand = cmd; + ds = new DataSet(); + da.Fill(ds); + return ds; } @@ -54,26 +45,26 @@ namespace AIAHTML5.API.Models ArrayList arrUserModules = new ArrayList(); - Hashtable userModuleHash = new Hashtable(); + Hashtable userModuleHash = new Hashtable(); - string sp = DBConstants.GET_ALL_MODULES; + string sp = DBConstants.GET_ALL_MODULES; - DataSet ds = DBModel.GetDataFromStoredProcedure(sp); + DataSet ds = DBModel.GetDataFromStoredProcedure(sp); - if (ds!= null && ds.Tables.Count > 0) - { - DataTable dt = ds.Tables[0]; + if (ds != null && ds.Tables.Count > 0) + { + DataTable dt = ds.Tables[0]; - foreach (DataRow drModule in dt.Rows) - { - userModuleHash = new Hashtable(); - userModuleHash.Add(AIAConstants.KEY_ID, drModule["Id"]); - userModuleHash.Add(AIAConstants.KEY_NAME, drModule["Name"]); - userModuleHash.Add(AIAConstants.KEY_SLUG, drModule["Slug"]); - arrUserModules.Add(userModuleHash); - } + foreach (DataRow drModule in dt.Rows) + { + userModuleHash = new Hashtable(); + userModuleHash.Add(AIAConstants.KEY_ID, drModule["Id"]); + userModuleHash.Add(AIAConstants.KEY_NAME, drModule["Name"]); + userModuleHash.Add(AIAConstants.KEY_SLUG, drModule["Slug"]); + arrUserModules.Add(userModuleHash); } - + } + return arrUserModules; } @@ -84,55 +75,55 @@ namespace AIAHTML5.API.Models User objUser = null; DBModel objModel = new DBModel(); - - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - SqlDataAdapter da = new SqlDataAdapter(); - SqlParameter param; - DataSet ds = new DataSet(); - cmd.Connection = conn; - cmd.CommandText = DBConstants.GET_USER_DELAILS_BY_LOGIN_ID; - cmd.CommandType = CommandType.StoredProcedure; + SqlConnection conn = new SqlConnection(dbConnectionString); + SqlCommand cmd = new SqlCommand(); + SqlDataAdapter da = new SqlDataAdapter(); + SqlParameter param; + DataSet ds = new DataSet(); - param = new SqlParameter("@sLoginId", loginId); - param.Direction = ParameterDirection.Input; - param.DbType = DbType.String; - cmd.Parameters.Add(param); - - da.SelectCommand = cmd; - DataTable dt = new DataTable(); - da.Fill(dt); - - - if (dt!= null && dt.Rows.Count > 0) - { - foreach (DataRow dr in dt.Rows) - { - int tempVal; - DateTime date; - objUser = new User(); + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_USER_DELAILS_BY_LOGIN_ID; + cmd.CommandType = CommandType.StoredProcedure; - objUser.Id = Convert.ToInt32(dr["Id"]); - objUser.FirstName = dr["FirstName"].ToString(); - objUser.LastName = dr["LastName"].ToString(); - objUser.EmailId = dr["EmailId"].ToString(); - objUser.LoginId = dr["LoginId"].ToString(); - objUser.Password = dr["Password"].ToString(); - objUser.SecurityQuestionId =Int32.TryParse(dr["SecurityQuestionId"].ToString(), out tempVal) ? tempVal : (int?)null; - objUser.SecurityAnswer = dr["SecurityAnswer"].ToString(); ; - objUser.CreatorId = Int32.TryParse(dr["CreatorId"].ToString(), out tempVal) ? tempVal : (int?)null; - objUser.CreationDate = Convert.ToDateTime(dr["CreationDate"]); - objUser.DeactivationDate = DateTime.TryParse(dr["DeactivationDate"].ToString(), out date) ? date : (DateTime?)null; - objUser.ModifierId = Int32.TryParse(dr["ModifierId"].ToString(), out tempVal) ? tempVal : (int?)null; - objUser.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null; - objUser.UserTypeId = Convert.ToInt32(dr["UserTypeId"]); - objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr["UserTypeId"])); - objUser.IsActive = Convert.ToBoolean(dr["IsActive"]); - } + param = new SqlParameter("@sLoginId", loginId); + param.Direction = ParameterDirection.Input; + param.DbType = DbType.String; + cmd.Parameters.Add(param); + + da.SelectCommand = cmd; + DataTable dt = new DataTable(); + da.Fill(dt); + + + if (dt != null && dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) + { + int tempVal; + DateTime date; + objUser = new User(); + + objUser.Id = Convert.ToInt32(dr["Id"]); + objUser.FirstName = dr["FirstName"].ToString(); + objUser.LastName = dr["LastName"].ToString(); + objUser.EmailId = dr["EmailId"].ToString(); + objUser.LoginId = dr["LoginId"].ToString(); + objUser.Password = dr["Password"].ToString(); + objUser.SecurityQuestionId = Int32.TryParse(dr["SecurityQuestionId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.SecurityAnswer = dr["SecurityAnswer"].ToString(); ; + objUser.CreatorId = Int32.TryParse(dr["CreatorId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.CreationDate = Convert.ToDateTime(dr["CreationDate"]); + objUser.DeactivationDate = DateTime.TryParse(dr["DeactivationDate"].ToString(), out date) ? date : (DateTime?)null; + objUser.ModifierId = Int32.TryParse(dr["ModifierId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null; + objUser.UserTypeId = Convert.ToInt32(dr["UserTypeId"]); + objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr["UserTypeId"])); + objUser.IsActive = Convert.ToBoolean(dr["IsActive"]); } - - + } + + return objUser; } @@ -142,33 +133,33 @@ namespace AIAHTML5.API.Models Hashtable hash = new Hashtable(); - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - SqlDataAdapter adapter; - SqlParameter param; - DataSet ds = new DataSet(); + SqlConnection conn = new SqlConnection(dbConnectionString); + SqlCommand cmd = new SqlCommand(); + SqlDataAdapter adapter; + SqlParameter param; + DataSet ds = new DataSet(); - cmd.Connection = conn; - cmd.CommandText = DBConstants.GET_LICENSE_DETAILS_BY_USER_ID; - cmd.CommandType = CommandType.StoredProcedure; + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_LICENSE_DETAILS_BY_USER_ID; + cmd.CommandType = CommandType.StoredProcedure; - param = new SqlParameter("@iUserId", userId); - param.Direction = ParameterDirection.Input; - param.DbType = DbType.Int32; - cmd.Parameters.Add(param); + param = new SqlParameter("@iUserId", userId); + param.Direction = ParameterDirection.Input; + param.DbType = DbType.Int32; + cmd.Parameters.Add(param); - adapter = new SqlDataAdapter(cmd); - adapter.Fill(ds); + adapter = new SqlDataAdapter(cmd); + adapter.Fill(ds); - if (ds!= null && ds.Tables.Count > 0) + if (ds != null && ds.Tables.Count > 0) + { + if (ds.Tables[0].Rows.Count > 0) { - if (ds.Tables[0].Rows.Count > 0) - { - hash.Add(AIAConstants.LICENSE_KEY_ID, ds.Tables[0].Rows[0][0]); - hash.Add(AIAConstants.EDITION_KEY_ID, ds.Tables[0].Rows[0][1]); - } + hash.Add(AIAConstants.LICENSE_KEY_ID, ds.Tables[0].Rows[0][0]); + hash.Add(AIAConstants.EDITION_KEY_ID, ds.Tables[0].Rows[0][1]); } - + } + return hash; } @@ -178,45 +169,45 @@ namespace AIAHTML5.API.Models ArrayList userModulelist = new ArrayList(); - Hashtable modulesHash; - DataSet ds = new DataSet(); + Hashtable modulesHash; + DataSet ds = new DataSet(); - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - SqlDataAdapter adapter; - SqlParameter param; + SqlConnection conn = new SqlConnection(dbConnectionString); + SqlCommand cmd = new SqlCommand(); + SqlDataAdapter adapter; + SqlParameter param; - cmd.Connection = conn; - cmd.CommandText = DBConstants.GET_USER_MODULES_BY_LICENSE_ID; - cmd.CommandType = CommandType.StoredProcedure; + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_USER_MODULES_BY_LICENSE_ID; + cmd.CommandType = CommandType.StoredProcedure; - param = new SqlParameter("@iLicenseId", licenseId); - param.Direction = ParameterDirection.Input; - param.DbType = DbType.Int32; - cmd.Parameters.Add(param); + param = new SqlParameter("@iLicenseId", licenseId); + param.Direction = ParameterDirection.Input; + param.DbType = DbType.Int32; + cmd.Parameters.Add(param); - adapter = new SqlDataAdapter(cmd); - adapter.Fill(ds); - + adapter = new SqlDataAdapter(cmd); + adapter.Fill(ds); - if (ds!=null && ds.Tables.Count > 0) - { - DataTable dt = ds.Tables[0]; - if (dt.Rows.Count > 0) + if (ds != null && ds.Tables.Count > 0) + { + DataTable dt = ds.Tables[0]; + + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) { - foreach (DataRow dr in dt.Rows) - { - modulesHash = new Hashtable(); - modulesHash.Add(AIAConstants.KEY_ID, dr["Id"]); - modulesHash.Add(AIAConstants.KEY_NAME, dr["Title"]); - modulesHash.Add(AIAConstants.KEY_SLUG, dr["Slug"]); - userModulelist.Add(modulesHash); - } + modulesHash = new Hashtable(); + modulesHash.Add(AIAConstants.KEY_ID, dr["Id"]); + modulesHash.Add(AIAConstants.KEY_NAME, dr["Title"]); + modulesHash.Add(AIAConstants.KEY_SLUG, dr["Slug"]); + userModulelist.Add(modulesHash); } } - - + } + + return userModulelist; } @@ -264,57 +255,57 @@ namespace AIAHTML5.API.Models User objUser = null; DBModel objModel = new DBModel(); - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - SqlDataAdapter adapter; - SqlParameter param; - DataSet ds = new DataSet(); + SqlConnection conn = new SqlConnection(dbConnectionString); + SqlCommand cmd = new SqlCommand(); + SqlDataAdapter adapter; + SqlParameter param; + DataSet ds = new DataSet(); - cmd.Connection = conn; - cmd.CommandText = DBConstants.GET_USER_DETAILS_BY_EMAILID; - cmd.CommandType = CommandType.StoredProcedure; + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_USER_DETAILS_BY_EMAILID; + cmd.CommandType = CommandType.StoredProcedure; - param = new SqlParameter("@sEmailId", emailId); - param.Direction = ParameterDirection.Input; - param.DbType = DbType.String; - cmd.Parameters.Add(param); + param = new SqlParameter("@sEmailId", emailId); + param.Direction = ParameterDirection.Input; + param.DbType = DbType.String; + cmd.Parameters.Add(param); - adapter = new SqlDataAdapter(cmd); - adapter.Fill(ds); + adapter = new SqlDataAdapter(cmd); + adapter.Fill(ds); - if (ds!= null && ds.Tables.Count > 0) - { - DataTable dt = ds.Tables[0]; + if (ds != null && ds.Tables.Count > 0) + { + DataTable dt = ds.Tables[0]; - if (dt.Rows.Count > 0) + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) { - foreach (DataRow dr in dt.Rows) - { - int tempVal; - DateTime date; - objUser = new User(); - - objUser.Id = Convert.ToInt32(dr["Id"]); - objUser.FirstName = dr["FirstName"].ToString(); - objUser.LastName = dr["LastName"].ToString(); - objUser.EmailId = dr["EmailId"].ToString(); - objUser.LoginId = dr["LoginId"].ToString(); - objUser.Password = dr["Password"].ToString(); - objUser.SecurityQuestionId = Int32.TryParse(dr["SecurityQuestionId"].ToString(), out tempVal) ? tempVal : (int?)null; - objUser.SecurityAnswer = dr["SecurityAnswer"].ToString(); ; - objUser.CreatorId = Int32.TryParse(dr["CreatorId"].ToString(), out tempVal) ? tempVal : (int?)null; - objUser.CreationDate = Convert.ToDateTime(dr["CreationDate"]); - objUser.DeactivationDate = DateTime.TryParse(dr["DeactivationDate"].ToString(), out date) ? date : (DateTime?)null; - objUser.ModifierId = Int32.TryParse(dr["ModifierId"].ToString(), out tempVal) ? tempVal : (int?)null; - objUser.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null; - objUser.UserTypeId = Convert.ToInt32(dr["UserTypeId"]); - objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr["UserTypeId"])); - objUser.IsActive = Convert.ToBoolean(dr["IsActive"]); - } + int tempVal; + DateTime date; + objUser = new User(); + + objUser.Id = Convert.ToInt32(dr["Id"]); + objUser.FirstName = dr["FirstName"].ToString(); + objUser.LastName = dr["LastName"].ToString(); + objUser.EmailId = dr["EmailId"].ToString(); + objUser.LoginId = dr["LoginId"].ToString(); + objUser.Password = dr["Password"].ToString(); + objUser.SecurityQuestionId = Int32.TryParse(dr["SecurityQuestionId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.SecurityAnswer = dr["SecurityAnswer"].ToString(); ; + objUser.CreatorId = Int32.TryParse(dr["CreatorId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.CreationDate = Convert.ToDateTime(dr["CreationDate"]); + objUser.DeactivationDate = DateTime.TryParse(dr["DeactivationDate"].ToString(), out date) ? date : (DateTime?)null; + objUser.ModifierId = Int32.TryParse(dr["ModifierId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null; + objUser.UserTypeId = Convert.ToInt32(dr["UserTypeId"]); + objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr["UserTypeId"])); + objUser.IsActive = Convert.ToBoolean(dr["IsActive"]); } } - + } + return objUser; } @@ -324,10 +315,11 @@ namespace AIAHTML5.API.Models int result = 0; + SqlConnection conn = null; try { conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); + SqlCommand cmd = new SqlCommand(); conn.Open(); cmd.Connection = conn; cmd.CommandText = DBConstants.UPDATE_USER_PASSWORD; @@ -336,7 +328,7 @@ namespace AIAHTML5.API.Models cmd.Parameters.AddWithValue("@sEmailId", emailId); cmd.Parameters.AddWithValue("@sNewPassword", userInfo["newPassword"].ToString()); result = cmd.ExecuteNonQuery(); - + } catch (SqlException ex) { @@ -356,53 +348,53 @@ namespace AIAHTML5.API.Models logger.Debug(" Inside GetLicenseSubscriptionDetailsByLicenseId for LicenseId = " + licenseId); LicenseSubscriptionDetails licenseSubscriptionDetails = null; - - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - SqlDataAdapter adapter; - SqlParameter param; - DataSet ds = new DataSet(); - cmd.Connection = conn; - cmd.CommandText = DBConstants.GET_SUBSCRIPTION_DETAILS_BY_LICENSE_ID; - cmd.CommandType = CommandType.StoredProcedure; + SqlConnection conn = new SqlConnection(dbConnectionString); + SqlCommand cmd = new SqlCommand(); + SqlDataAdapter adapter; + SqlParameter param; + DataSet ds = new DataSet(); - param = new SqlParameter("@iLicenseId", licenseId); - param.Direction = ParameterDirection.Input; - param.DbType = DbType.Int32; - cmd.Parameters.Add(param); + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_SUBSCRIPTION_DETAILS_BY_LICENSE_ID; + cmd.CommandType = CommandType.StoredProcedure; - adapter = new SqlDataAdapter(cmd); - adapter.Fill(ds); + param = new SqlParameter("@iLicenseId", licenseId); + param.Direction = ParameterDirection.Input; + param.DbType = DbType.Int32; + cmd.Parameters.Add(param); - if (ds!= null && ds.Tables.Count > 0) - { - licenseSubscriptionDetails = new LicenseSubscriptionDetails(); - DataTable dt = ds.Tables[0]; + adapter = new SqlDataAdapter(cmd); + adapter.Fill(ds); + + if (ds != null && ds.Tables.Count > 0) + { + licenseSubscriptionDetails = new LicenseSubscriptionDetails(); + DataTable dt = ds.Tables[0]; - if (dt.Rows.Count > 0) + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) { - foreach (DataRow dr in dt.Rows) - { - int tempVal; - DateTime date; - licenseSubscriptionDetails.Id = Convert.ToInt32(dr["Id"]); - licenseSubscriptionDetails.LicenseId = Convert.ToInt32(dr["LicenseId"]); - licenseSubscriptionDetails.SubscriptionPlanId = Int32.TryParse(dr["SubscriptionPlanId"].ToString(), out tempVal) ? tempVal : (int?)null; - licenseSubscriptionDetails.SubscriptionValidFrom = DateTime.TryParse(dr["SubscriptionValidFrom"].ToString(), out date) ? date : (DateTime?)null; - licenseSubscriptionDetails.SubscriptionValidThrough = DateTime.TryParse(dr["SubscriptionValidThrough"].ToString(), out date) ? date : (DateTime?)null; - licenseSubscriptionDetails.RenewalDate = DateTime.TryParse(dr["RenewalDate"].ToString(), out date) ? date : (DateTime?)null; - licenseSubscriptionDetails.PaymentMode = dr["PaymentMode"].ToString(); - licenseSubscriptionDetails.TotalAmount = Convert.ToDouble(dr["TotalAmount"]); - licenseSubscriptionDetails.AmountPaid = Convert.ToDouble(dr["AmountPaid"]); - licenseSubscriptionDetails.AmountPending = Convert.ToDouble(dr["AmountPending"]); - licenseSubscriptionDetails.NoOfImages = Convert.ToInt32(dr["NoofImages"]); - } + int tempVal; + DateTime date; + licenseSubscriptionDetails.Id = Convert.ToInt32(dr["Id"]); + licenseSubscriptionDetails.LicenseId = Convert.ToInt32(dr["LicenseId"]); + licenseSubscriptionDetails.SubscriptionPlanId = Int32.TryParse(dr["SubscriptionPlanId"].ToString(), out tempVal) ? tempVal : (int?)null; + licenseSubscriptionDetails.SubscriptionValidFrom = DateTime.TryParse(dr["SubscriptionValidFrom"].ToString(), out date) ? date : (DateTime?)null; + licenseSubscriptionDetails.SubscriptionValidThrough = DateTime.TryParse(dr["SubscriptionValidThrough"].ToString(), out date) ? date : (DateTime?)null; + licenseSubscriptionDetails.RenewalDate = DateTime.TryParse(dr["RenewalDate"].ToString(), out date) ? date : (DateTime?)null; + licenseSubscriptionDetails.PaymentMode = dr["PaymentMode"].ToString(); + licenseSubscriptionDetails.TotalAmount = Convert.ToDouble(dr["TotalAmount"]); + licenseSubscriptionDetails.AmountPaid = Convert.ToDouble(dr["AmountPaid"]); + licenseSubscriptionDetails.AmountPending = Convert.ToDouble(dr["AmountPending"]); + licenseSubscriptionDetails.NoOfImages = Convert.ToInt32(dr["NoofImages"]); } } - - - + } + + + return licenseSubscriptionDetails; } @@ -411,65 +403,65 @@ namespace AIAHTML5.API.Models logger.Debug(" inside GetLicenseDetailsByLicenseId for LicenseId = " + licenseId); License license = null; - - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - SqlDataAdapter adapter; - SqlParameter param; - DataSet ds = new DataSet(); - cmd.Connection = conn; - cmd.CommandText = DBConstants.GET_LICENSE_DETAILS_BY_ID; - cmd.CommandType = CommandType.StoredProcedure; + SqlConnection conn = new SqlConnection(dbConnectionString); + SqlCommand cmd = new SqlCommand(); + SqlDataAdapter adapter; + SqlParameter param; + DataSet ds = new DataSet(); - param = new SqlParameter("@Id", licenseId); - param.Direction = ParameterDirection.Input; - param.DbType = DbType.Int32; - cmd.Parameters.Add(param); + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_LICENSE_DETAILS_BY_ID; + cmd.CommandType = CommandType.StoredProcedure; - adapter = new SqlDataAdapter(cmd); - adapter.Fill(ds); + param = new SqlParameter("@Id", licenseId); + param.Direction = ParameterDirection.Input; + param.DbType = DbType.Int32; + cmd.Parameters.Add(param); - if (ds!= null && ds.Tables.Count > 0) + adapter = new SqlDataAdapter(cmd); + adapter.Fill(ds); + + if (ds != null && ds.Tables.Count > 0) + { + + DataTable dt = ds.Tables[0]; + if (dt.Rows.Count > 0) { - - DataTable dt = ds.Tables[0]; - if (dt.Rows.Count > 0) - { - license = new License(); + license = new License(); - foreach (DataRow dr in dt.Rows) - { - DateTime date; - license.Id = Convert.ToInt32(dr["Id"]); - license.AccountNumber = dr["AccountNumber"].ToString(); - license.LicenseeFirstName = dr["LicenseeFirstName"].ToString(); - license.LicenseeLastName = dr["LicenseeLastName"].ToString(); - license.LicenseTypeId = Convert.ToInt32(dr["LicenseTypeId"]); - license.InstitutionName = dr["InstitutionName"].ToString(); - license.Address1 = dr["Address1"].ToString(); - license.Address2 = dr["Address2"].ToString(); - license.CountryId = Convert.ToInt32(dr["CountryId"]); - license.StateId = Convert.ToInt32(dr["StateId"]); - license.City = dr["City"].ToString(); - license.Zip = dr["Zip"].ToString(); - license.Phone = dr["Phone"].ToString(); - license.EmailId = dr["EmailId"].ToString(); - license.TotalLogins = Convert.ToInt32(dr["TotalLogins"]); - license.AccountTypeId = Convert.ToInt32(dr["AccountTypeId"]); - license.IsActive = Convert.ToBoolean(dr["IsActive"]); - license.IsDistrictSiteLicense = Convert.ToBoolean(dr["IsDistrictSiteLicense"]); - license.CreationDate = Convert.ToDateTime(dr["CreationDate"]); - license.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null; - license.NoOfRenewals = Convert.ToInt32(dr["NoOfRenewals"]); - license.IsTermAccepted = Convert.ToBoolean(dr["IsTermsAccepted"]); - license.ProductId = dr["ProductId"].ToString(); - } + foreach (DataRow dr in dt.Rows) + { + DateTime date; + license.Id = Convert.ToInt32(dr["Id"]); + license.AccountNumber = dr["AccountNumber"].ToString(); + license.LicenseeFirstName = dr["LicenseeFirstName"].ToString(); + license.LicenseeLastName = dr["LicenseeLastName"].ToString(); + license.LicenseTypeId = Convert.ToInt32(dr["LicenseTypeId"]); + license.InstitutionName = dr["InstitutionName"].ToString(); + license.Address1 = dr["Address1"].ToString(); + license.Address2 = dr["Address2"].ToString(); + license.CountryId = Convert.ToInt32(dr["CountryId"]); + license.StateId = Convert.ToInt32(dr["StateId"]); + license.City = dr["City"].ToString(); + license.Zip = dr["Zip"].ToString(); + license.Phone = dr["Phone"].ToString(); + license.EmailId = dr["EmailId"].ToString(); + license.TotalLogins = Convert.ToInt32(dr["TotalLogins"]); + license.AccountTypeId = Convert.ToInt32(dr["AccountTypeId"]); + license.IsActive = Convert.ToBoolean(dr["IsActive"]); + license.IsDistrictSiteLicense = Convert.ToBoolean(dr["IsDistrictSiteLicense"]); + license.CreationDate = Convert.ToDateTime(dr["CreationDate"]); + license.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null; + license.NoOfRenewals = Convert.ToInt32(dr["NoOfRenewals"]); + license.IsTermAccepted = Convert.ToBoolean(dr["IsTermsAccepted"]); + license.ProductId = dr["ProductId"].ToString(); } } - - - + } + + + return license; } @@ -478,18 +470,18 @@ namespace AIAHTML5.API.Models logger.Debug(" inside UpdateLicenseTermStatus for AccountNumber = " + accountNumber); int result = 0; - + SqlConnection conn = null; try - { + { conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); + SqlCommand cmd = new SqlCommand(); conn.Open(); cmd.Connection = conn; cmd.CommandText = DBConstants.UPDATE_LICENSE_TERM_STATUS; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@sAccountNumber", accountNumber); result = cmd.ExecuteNonQuery(); - + } catch (SqlException ex) { @@ -509,28 +501,28 @@ namespace AIAHTML5.API.Models ArrayList arrTermsAndConditions = new ArrayList(); - - Hashtable contentHash = null; - string str = string.Empty; - string spName = DBConstants.GET_TERMS_AND_CONDITIONS; - DataSet ds = DBModel.GetDataFromStoredProcedure(spName); - if (ds!= null && ds.Tables.Count > 0) + Hashtable contentHash = null; + string str = string.Empty; + string spName = DBConstants.GET_TERMS_AND_CONDITIONS; + DataSet ds = DBModel.GetDataFromStoredProcedure(spName); + + if (ds != null && ds.Tables.Count > 0) + { + DataTable dt = ds.Tables[0]; + if (dt.Rows.Count > 0) { - DataTable dt = ds.Tables[0]; - if (dt.Rows.Count > 0) + foreach (DataRow dr in dt.Rows) { - foreach (DataRow dr in dt.Rows) - { - contentHash = new Hashtable(); - contentHash.Add(AIAConstants.KEY_TITLE, dr["Title"]); - contentHash.Add(AIAConstants.KEY_CONTENT, dr["Content"]); - arrTermsAndConditions.Add(contentHash); - } + contentHash = new Hashtable(); + contentHash.Add(AIAConstants.KEY_TITLE, dr["Title"]); + contentHash.Add(AIAConstants.KEY_CONTENT, dr["Content"]); + arrTermsAndConditions.Add(contentHash); } } - - + } + + return arrTermsAndConditions; } @@ -539,10 +531,11 @@ namespace AIAHTML5.API.Models logger.Debug(" inside InsertLoginDetails for UserId= " + userId); int result = 0; + SqlConnection conn = null; try { conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); + SqlCommand cmd = new SqlCommand(); conn.Open(); cmd.Connection = conn; cmd.CommandText = DBConstants.INSERT_LOGIN_DETAIL; @@ -568,10 +561,11 @@ namespace AIAHTML5.API.Models logger.Debug(" inside InsertIncorrectLoginAttempts for UserId= " + userId); int result = 0; + SqlConnection conn = null; try { conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); + SqlCommand cmd = new SqlCommand(); conn.Open(); cmd.Connection = conn; cmd.CommandText = DBConstants.INSERT_INCORRECT_LOGIN_ATTEMPTS; @@ -596,35 +590,35 @@ namespace AIAHTML5.API.Models logger.Debug(" inside GetIncorrectLoginAttempts for UserId = " + userId); int count = 0; - - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - cmd.Connection = conn; - cmd.CommandText = DBConstants.GET_INCORRECT_LOGIN_ATTEMPTS; - cmd.CommandType = CommandType.StoredProcedure; - cmd.Parameters.AddWithValue("@iUserId", userId); - SqlDataAdapter da = new SqlDataAdapter(); - da.SelectCommand = cmd; - DataSet ds = new DataSet(); - da.Fill(ds); - if (ds!= null && ds.Tables.Count > 0) - { - DataTable dt = ds.Tables[0]; + SqlConnection conn = new SqlConnection(dbConnectionString); + SqlCommand cmd = new SqlCommand(); + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_INCORRECT_LOGIN_ATTEMPTS; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@iUserId", userId); + SqlDataAdapter da = new SqlDataAdapter(); + da.SelectCommand = cmd; + DataSet ds = new DataSet(); + da.Fill(ds); + + if (ds != null && ds.Tables.Count > 0) + { + DataTable dt = ds.Tables[0]; - if (dt.Rows.Count > 0) + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) { - foreach (DataRow dr in dt.Rows) + foreach (DataColumn dc in dt.Columns) { - foreach (DataColumn dc in dt.Columns) - { - count = Convert.ToInt32(dr[dc]); - } + count = Convert.ToInt32(dr[dc]); } } } - - + } + + return count; } @@ -633,10 +627,11 @@ namespace AIAHTML5.API.Models logger.Debug(" inside UpdateIncorrectLoginAttempts for UserId= " + userId); int result = 0; + SqlConnection conn = null; try { conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); + SqlCommand cmd = new SqlCommand(); conn.Open(); cmd.Connection = conn; cmd.CommandText = DBConstants.UPDATE_INCORRECT_LOGIN_ATTEMPTS; @@ -661,10 +656,11 @@ namespace AIAHTML5.API.Models logger.Debug(" inside DeleteIncorrectLoginAttempts for UserId= " + userId); int result = 0; + SqlConnection conn = null; try { conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); + SqlCommand cmd = new SqlCommand(); conn.Open(); cmd.Connection = conn; cmd.CommandText = DBConstants.DELETE_INCORRECT_LOGIN_ATTEMPTS; @@ -690,28 +686,28 @@ namespace AIAHTML5.API.Models ArrayList failureCauseList = new ArrayList(); - Hashtable fcHash = null; + Hashtable fcHash = null; - string sp = DBConstants.GET_ALL_LOGIN_FAILURE_CAUSES; + string sp = DBConstants.GET_ALL_LOGIN_FAILURE_CAUSES; - DataSet ds = DBModel.GetDataFromStoredProcedure(sp); + DataSet ds = DBModel.GetDataFromStoredProcedure(sp); - if (ds.Tables.Count > 0) - { - DataTable dt = ds.Tables[0]; + if (ds.Tables.Count > 0) + { + DataTable dt = ds.Tables[0]; - if (dt.Rows.Count > 0) + if (dt.Rows.Count > 0) + { + foreach (DataRow drFailureCause in dt.Rows) { - foreach (DataRow drFailureCause in dt.Rows) - { - fcHash = new Hashtable(); - fcHash.Add(AIAConstants.KEY_ID, drFailureCause["Id"]); - fcHash.Add(AIAConstants.KEY_DESCRIPTION, drFailureCause["Description"]); - failureCauseList.Add(fcHash); - } + fcHash = new Hashtable(); + fcHash.Add(AIAConstants.KEY_ID, drFailureCause["Id"]); + fcHash.Add(AIAConstants.KEY_DESCRIPTION, drFailureCause["Description"]); + failureCauseList.Add(fcHash); } } - + } + return failureCauseList; } @@ -720,10 +716,11 @@ namespace AIAHTML5.API.Models logger.Debug(" inside InsertUserLoginLog for AccountNumber= " + accountNumber); int result = 0; + SqlConnection conn = null; try { conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); + SqlCommand cmd = new SqlCommand(); conn.Open(); cmd.Connection = conn; cmd.CommandText = DBConstants.INSERT_LOGIN_ERROR_LOG; @@ -754,35 +751,35 @@ namespace AIAHTML5.API.Models BlockedUser blockedUser = null; DataTable dt = null; - - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - cmd.Connection = conn; - cmd.CommandText = DBConstants.GET_BLOCKED_USER_BY_USER_ID; - cmd.CommandType = CommandType.StoredProcedure; - cmd.Parameters.AddWithValue("@userId", userId); - SqlDataAdapter da = new SqlDataAdapter(); - da.SelectCommand = cmd; - dt = new DataTable(); - da.Fill(dt); - if (dt!= null && dt.Rows.Count > 0) + SqlConnection conn = new SqlConnection(dbConnectionString); + SqlCommand cmd = new SqlCommand(); + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_BLOCKED_USER_BY_USER_ID; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@userId", userId); + SqlDataAdapter da = new SqlDataAdapter(); + da.SelectCommand = cmd; + dt = new DataTable(); + da.Fill(dt); + + if (dt != null && dt.Rows.Count > 0) + { + blockedUser = new BlockedUser(); + foreach (DataRow dr in dt.Rows) { - blockedUser = new BlockedUser(); - foreach (DataRow dr in dt.Rows) - { - blockedUser.Id = Convert.ToInt32(dr["Id"]); - blockedUser.FirstName = dr["FirstName"].ToString(); - blockedUser.LastName = dr["LastName"].ToString(); - blockedUser.EmailId = dr["EmailId"].ToString(); - blockedUser.LoginId = dr["LoginId"].ToString(); - blockedUser.Password = dr["Password"].ToString(); - blockedUser.AccountNumber = dr["AccountNumber"].ToString(); - blockedUser.LoginTime = Convert.ToDateTime(dr["LoginTime"]); - } + blockedUser.Id = Convert.ToInt32(dr["Id"]); + blockedUser.FirstName = dr["FirstName"].ToString(); + blockedUser.LastName = dr["LastName"].ToString(); + blockedUser.EmailId = dr["EmailId"].ToString(); + blockedUser.LoginId = dr["LoginId"].ToString(); + blockedUser.Password = dr["Password"].ToString(); + blockedUser.AccountNumber = dr["AccountNumber"].ToString(); + blockedUser.LoginTime = Convert.ToDateTime(dr["LoginTime"]); } - - + } + + return blockedUser; } @@ -793,39 +790,39 @@ namespace AIAHTML5.API.Models ArrayList blockedUsersList = new ArrayList(); BlockedUser blockedUser = null; DataTable dt = null; - - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - cmd.Connection = conn; - cmd.CommandText = DBConstants.GET_BLOCKED_USERS_BY_USER_TYPE; - cmd.CommandType = CommandType.StoredProcedure; - cmd.Parameters.AddWithValue("@iUserTypeId", userTypeId); - SqlDataAdapter da = new SqlDataAdapter(); - da.SelectCommand = cmd; - dt = new DataTable(); - da.Fill(dt); - if (dt.Rows.Count > 0) + SqlConnection conn = new SqlConnection(dbConnectionString); + SqlCommand cmd = new SqlCommand(); + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_BLOCKED_USERS_BY_USER_TYPE; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@iUserTypeId", userTypeId); + SqlDataAdapter da = new SqlDataAdapter(); + da.SelectCommand = cmd; + dt = new DataTable(); + da.Fill(dt); + + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) { - foreach (DataRow dr in dt.Rows) - { - blockedUser = new BlockedUser(); - - blockedUser.Id = Convert.ToInt32(dr["Id"]); - blockedUser.FirstName = dr["FirstName"].ToString(); - blockedUser.LastName = dr["LastName"].ToString(); - blockedUser.EmailId = dr["EmailId"].ToString(); - blockedUser.LoginId = dr["LoginId"].ToString(); - blockedUser.Password = dr["Password"].ToString(); - blockedUser.AccountNumber = dr["AccountNumber"].ToString(); - blockedUser.LoginTime = Convert.ToDateTime(dr["LoginTime"]); - - blockedUsersList.Add(blockedUser); - } + blockedUser = new BlockedUser(); + + blockedUser.Id = Convert.ToInt32(dr["Id"]); + blockedUser.FirstName = dr["FirstName"].ToString(); + blockedUser.LastName = dr["LastName"].ToString(); + blockedUser.EmailId = dr["EmailId"].ToString(); + blockedUser.LoginId = dr["LoginId"].ToString(); + blockedUser.Password = dr["Password"].ToString(); + blockedUser.AccountNumber = dr["AccountNumber"].ToString(); + blockedUser.LoginTime = Convert.ToDateTime(dr["LoginTime"]); + + blockedUsersList.Add(blockedUser); } - - - + } + + + return blockedUsersList; } @@ -862,7 +859,7 @@ namespace AIAHTML5.API.Models throw; } - return result; + return result; } } } \ No newline at end of file