public ReturnInfo GetUserByUserId(SmartDB dbInstance, string UserId, out UserInfo info) { bool flag = string.IsNullOrEmpty(UserId); ReturnInfo result; if (flag) { info = null; result = new ReturnInfo(ErrorEnum.NullReference, "User Id is required"); } else { IInfo record = UserInfoBLL.dal.GetRecord(dbInstance, UserId, out info); bool flag2 = record.Code > ErrorEnum.NoError; if (flag2) { result = new ReturnInfo(record.Code, record.Message); } else { result = new ReturnInfo(); } } return(result); }
public ReturnInfo GetUserList(SmartDB dbInstance) { IInfo records = UserInfoBLL.dal.GetRecords(dbInstance, "REPORT USERINFO_LST", null); return(new ReturnInfo { Code = records.Code, Message = records.Message, BizObject = ((records.Code == ErrorEnum.NoError) ? records.BizObject : new List <Model.UserInfo>()) }); }
public ReturnInfo Update(SmartDB dbInstance, UserInfo info) { bool flag = string.IsNullOrEmpty(info.Username); ReturnInfo result; if (flag) { result = new ReturnInfo(ErrorEnum.NullReference, "Username is required"); } else { bool flag2 = info.Username.Trim().Length < 5; if (flag2) { result = new ReturnInfo(ErrorEnum.InvalidInput, "Invalid Username"); } else { bool flag3 = string.IsNullOrEmpty(info.Password) || string.IsNullOrWhiteSpace(info.Password); if (flag3) { result = new ReturnInfo(ErrorEnum.NullReference, "Password is required"); } else { bool flag4 = info.Password.Length < 8; if (flag4) { result = new ReturnInfo(ErrorEnum.InvalidInput, "Invalid Password"); } else { bool flag5 = string.IsNullOrWhiteSpace(info.Name) || string.IsNullOrEmpty(info.Name); if (flag5) { result = new ReturnInfo(ErrorEnum.NullReference, "Name is required"); } else { IInfo info2 = UserInfoBLL.dal.Update(dbInstance, info); result = new ReturnInfo(info2.Code, info2.Message, info2.RowsAffected); } } } } } return(result); }
public ReturnInfo Remove(SmartDB dbInstance, long Id) { bool flag = Id <= 0L; ReturnInfo result; if (flag) { result = new ReturnInfo(ErrorEnum.InvalidInput, "Invalid ID"); } else { IInfo info = UserInfoBLL.dal.Remove(dbInstance, Id); result = new ReturnInfo(info.Code, info.Message, info.RowsAffected); } return(result); }
public ReturnInfo GetUsersByName(SmartDB dbInstance, string name) { string cmdText = "[REPORT USERINFO_NAME]"; SqlParameter[] array = new SqlParameter[] { new SqlParameter("@Name", SqlDbType.NVarChar) }; array[0].Value = name; IInfo records = UserInfoBLL.dal.GetRecords(dbInstance, cmdText, array); return(new ReturnInfo { Code = records.Code, Message = records.Message, BizObject = ((records.Code == ErrorEnum.NoError) ? records.BizObject : new List <UserInfo>()) }); }
public ReturnInfo GetUserByUsername(SmartDB dbInstance, string username) { string sQL_GET = "REPORT USERINFO_USERNAME"; SqlParameter[] array = new SqlParameter[] { new SqlParameter("@Username", SqlDbType.NVarChar) }; array[0].Value = username; IInfo record = UserInfoBLL.dal.GetRecord(dbInstance, sQL_GET, array); return(new ReturnInfo { BizObject = ((record.Code == ErrorEnum.NoError) ? record.BizObject : null), Code = record.Code, Message = record.Message, RowsAffected = record.RowsAffected }); }
public ReturnInfo GetUserByUsernamePassword(SmartDB dbInstance, string username, string password) { string cmdText = "[REPORT USERINFO_USERNAME_PASSWORD]"; SqlParameter[] array = new SqlParameter[] { new SqlParameter("@Username", SqlDbType.NVarChar), new SqlParameter("@Password", SqlDbType.NVarChar) }; array[0].Value = username; array[1].Value = password; IInfo records = UserInfoBLL.dal.GetRecord(dbInstance, cmdText, array); return(new ReturnInfo { Code = records.Code, Message = records.Message, BizObject = ((records.Code == ErrorEnum.NoError) ? records.BizObject : new List <Model.UserInfo>()) }); }
public ReturnInfo Create(SmartDB dbInstance, ref UserInfo info) { bool flag = info.Username.Trim().Length < 5; ReturnInfo result; if (flag) { result = new ReturnInfo(ErrorEnum.InvalidInput, "Username too short! Minimum 6 characters."); } else { bool flag2 = info.Password.Trim().Length < 8; if (flag2) { result = new ReturnInfo(ErrorEnum.InvalidInput, "Password too short! Minimum 8 characters."); } else { bool flag3 = info.Name.Trim().Length < 8; if (flag3) { result = new ReturnInfo(ErrorEnum.InvalidInput, "Name too short! Minimum 8 characters."); } else { IInfo info2 = UserInfoBLL.dal.Insert(dbInstance, ref info); bool flag4 = info2.Code == ErrorEnum.NoError; if (flag4) { result = new ReturnInfo(info2.Code, info2.Message); } else { result = new ReturnInfo(info2.Code, info2.Message); } } } } return(result); }
public static SqlParameter[] GetParameters(SmartDB dbInstance, string cacheKey) { bool transactionControl = dbInstance.TransactionControl; SqlCommand sqlCommand; if (transactionControl) { sqlCommand = new SqlCommand(cacheKey, dbInstance.Connection, dbInstance.Transaction) { CommandType = CommandType.StoredProcedure }; } else { sqlCommand = new SqlCommand(cacheKey, dbInstance.Connection) { CommandType = CommandType.StoredProcedure }; } bool flag = dbInstance.Connection.State == ConnectionState.Closed; if (flag) { dbInstance.Connection.Open(); } SqlCommandBuilder.DeriveParameters(sqlCommand); SqlParameter[] array = new SqlParameter[sqlCommand.Parameters.Count - 1]; int i = 1; int count = sqlCommand.Parameters.Count; while (i < count) { array[i - 1] = (SqlParameter)((ICloneable)sqlCommand.Parameters[i]).Clone(); i++; } SqlHelper.CacheParameters(cacheKey, array); return(array); }
public virtual IInfo Delete(SmartDB dbInstance, object Id) { int rowsAffected = 0; string sQL_DELETE = this.SQL_DELETE; SqlParameter[] array = new SqlParameter[] { new SqlParameter(this.PARM_ID, SqlDbType.NVarChar) }; array[0].Value = Id; IInfo result; try { bool transactionControl = dbInstance.TransactionControl; if (transactionControl) { rowsAffected = SqlHelper.ExecuteNonQuery(dbInstance.Transaction, CommandType.StoredProcedure, sQL_DELETE, array); } else { rowsAffected = SqlHelper.ExecuteNonQuery(dbInstance.Connection.ConnectionString, CommandType.StoredProcedure, sQL_DELETE, array); } } catch (Exception ex) { bool flag = ex.Message.Contains("COLUMN REFERENCE"); if (flag) { result = new ReturnInfo(ErrorEnum.ColumnReference, "Record is still in use or being referenced by other object"); return(result); } result = new ReturnInfo(ErrorEnum.DataException, ex.Message); return(result); } result = new ReturnInfo(ErrorEnum.NoError, "", rowsAffected); return(result); }
public ReturnInfo UpdateLoginStatus(SmartDB dbInstance, string username, bool isActive) { bool flag = string.IsNullOrEmpty(username); ReturnInfo result; if (flag) { result = new ReturnInfo(ErrorEnum.NullReference, "User Id is required"); } else { bool flag2 = username.Trim().Length < 5; if (flag2) { result = new ReturnInfo(ErrorEnum.InvalidInput, "Invalid User ID"); } else { IInfo info = UserInfoBLL.dal.UpdateLoginStatus(dbInstance, username, isActive); result = new ReturnInfo(info.Code, info.Message, info.RowsAffected); } } return(result); }
public virtual IInfo Insert(SmartDB dbInstance, ModelInfo info) { SqlParameter[] insertParameters = this.GetInsertParameters(dbInstance); string sQL_INSERT = this.SQL_INSERT; IInfo result; try { for (int i = 0; i < insertParameters.Length; i++) { string fieldname = insertParameters[i].ParameterName.Remove(0, 1); bool flag = info[fieldname] == null; if (flag) { insertParameters[i].Value = DBNull.Value; } else { bool flag2 = insertParameters[i].DbType == DbType.DateTime || insertParameters[i].DbType == DbType.Date || insertParameters[i].DbType == DbType.DateTime2; if (flag2) { insertParameters[i].Value = Convert.ToDateTime(info[fieldname]).ToString("dd-MMM-yyyy hh:mm:ss tt"); } else { insertParameters[i].Value = info[fieldname]; } } } } catch (Exception ex) { bool flag3 = ex.Message.Contains("null reference"); if (flag3) { result = new ReturnInfo(ErrorEnum.NullReference, ex.Message); return(result); } result = new ReturnInfo(ErrorEnum.Exception, ex.Message); return(result); } SqlDataReader sqlDataReader = null; try { bool transactionControl = dbInstance.TransactionControl; if (transactionControl) { sqlDataReader = SqlHelper.ExecuteReader(dbInstance.Transaction, CommandType.StoredProcedure, sQL_INSERT, insertParameters); } else { sqlDataReader = SqlHelper.ExecuteReader(dbInstance.Connection.ConnectionString, CommandType.StoredProcedure, sQL_INSERT, insertParameters); } //bool flag4 = !sqlDataReader.Read(); bool flag4 = sqlDataReader.Read(); if (flag4) { sqlDataReader.Dispose(); result = new ReturnInfo(ErrorEnum.TransactionError, "Insert record failed"); return(result); } //bool flag5 = sqlDataReader.GetDecimal(0) == -99m; //if (flag5) //{ // sqlDataReader.Dispose(); // result = new ReturnInfo(ErrorEnum.DuplicateRecord, "Record already exists"); // return result; //} //bool flag6 = sqlDataReader.GetDecimal(0) == decimal.MinusOne; //if (flag6) //{ // sqlDataReader.Dispose(); // result = new ReturnInfo(ErrorEnum.TransactionError, "Insert record failed"); // return result; //} string fieldname2 = this.PARM_ID.Remove(0, 1); //info[fieldname2] = Convert.ToInt32(sqlDataReader.GetDecimal(0)); } catch (Exception ex2) { Debug.WriteLine($"ex2 {ex2}"); bool flag7 = ex2.Message.Contains("unique constraint"); if (flag7) { result = new ReturnInfo(ErrorEnum.UniqueConstraint, "Record already exist in the system"); return(result); } result = new ReturnInfo(ErrorEnum.DataException, ex2.Message); return(result); } finally { bool flag8 = sqlDataReader != null; if (flag8) { sqlDataReader.Dispose(); } } result = new ReturnInfo { Code = ErrorEnum.NoError, Message = "", BizObject = info, RowsAffected = 1 }; return(result); }
protected virtual SqlParameter[] GetUpdateParameters(SmartDB dbInstance) { return(SqlHelper.GetParameters(new SmartDB(), this.SQL_UPDATE)); }
public virtual IInfo GetRecords(SmartDB dbInstance) { return(null); }
public virtual IInfo GetRecord(SmartDB dbInstance, object Id) { return(null); }
protected virtual SqlParameter[] GetInsertParameters(SmartDB dbInstance) { return(SqlHelper.GetParameters(new SmartDB(), this.SQL_INSERT)); }
public virtual IInfo Update(SmartDB dbInstance, ModelInfo info) { int rowsAffected = 0; SqlParameter[] updateParameters = this.GetUpdateParameters(dbInstance); string sQL_UPDATE = this.SQL_UPDATE; IInfo result; try { for (int i = 0; i < updateParameters.Length; i++) { string fieldname = updateParameters[i].ParameterName.Remove(0, 1); bool flag = info[fieldname] == null; if (flag) { updateParameters[i].Value = DBNull.Value; } else { bool flag2 = updateParameters[i].DbType == DbType.DateTime || updateParameters[i].DbType == DbType.Date || updateParameters[i].DbType == DbType.DateTime2; if (flag2) { updateParameters[i].Value = Convert.ToDateTime(info[fieldname]).ToString("dd-MMM-yyyy"); } else { updateParameters[i].Value = info[fieldname]; } } } } catch (Exception ex) { bool flag3 = ex.Message.Contains("null reference"); if (flag3) { result = new ReturnInfo(ErrorEnum.NullReference, ex.Message); return(result); } result = new ReturnInfo(ErrorEnum.Exception, ex.Message); return(result); } try { bool transactionControl = dbInstance.TransactionControl; if (transactionControl) { rowsAffected = SqlHelper.ExecuteNonQuery(dbInstance.Transaction, CommandType.StoredProcedure, sQL_UPDATE, updateParameters); } else { rowsAffected = SqlHelper.ExecuteNonQuery(dbInstance.Connection.ConnectionString, CommandType.StoredProcedure, sQL_UPDATE, updateParameters); } } catch (Exception ex2) { bool flag4 = ex2.Message.Contains("unique constraint"); if (flag4) { result = new ReturnInfo(ErrorEnum.UniqueConstraint, string.Format("Record: {0} already exist in the system", info["Id"])); return(result); } result = new ReturnInfo(ErrorEnum.DataException, ex2.Message); return(result); } result = new ReturnInfo(ErrorEnum.NoError, "", rowsAffected); return(result); }