Exemple #1
0
        private USERDC FillObject(IDataReader reader)
        {
            USERDC objUSER = null;

            if (reader != null && reader.Read())
            {
                objUSER                   = new USERDC();
                objUSER.USER_ID           = (int)reader["USER_ID"];
                objUSER.USER_NAME         = (String)reader["USER_NAME"];
                objUSER.PASSWORD          = (String)reader["PASSWORD"];
                objUSER.FIRST_NAME        = (String)reader["FIRST_NAME"];
                objUSER.LAST_NAME         = (String)reader["LAST_NAME"];
                objUSER.ROLE.ROLE_ID      = (int)reader["ROLE_ID"];
                objUSER.ROLE.ROLE_NAME    = (String)reader["ROLE_NAME"];
                objUSER.USER_COMPANIES    = reader["COMPANIES"] == DBNull.Value ? new int[] { } : Array.ConvertAll <string, int>(((String)reader["COMPANIES"]).Split(','), Convert.ToInt32);
                objUSER.EMAIL_ADDRESS     = (String)reader["EMAIL_ADDRESS"];
                objUSER.OFFICE_PHONE      = reader["OFFICE_PHONE"] == DBNull.Value ? null : (String)reader["OFFICE_PHONE"];
                objUSER.MOBILE_PHONE      = reader["MOBILE_PHONE"] == DBNull.Value ? null : (String)reader["MOBILE_PHONE"];
                objUSER.SECURITY_QUESTION = reader["SECURITY_QUESTION"] == DBNull.Value ? null : (String)reader["SECURITY_QUESTION"];
                objUSER.ANSWER            = reader["ANSWER"] == DBNull.Value ? null : (String)reader["ANSWER"];
                objUSER.STATUS            = (String)reader["STATUS"];
                objUSER.CREATED_ON        = (DateTime)reader["CREATED_ON"];
                objUSER.CREATED_BY        = (int)reader["CREATED_BY"];
                objUSER.MODIFIED_ON       = (DateTime)reader["MODIFIED_ON"];
                objUSER.MODIFIED_BY       = (int)reader["MODIFIED_BY"];
                objUSER.LOCK_COUNTER      = (!string.IsNullOrEmpty(reader["LOCK_COUNTER"].ToString()) ? (int)reader["LOCK_COUNTER"] : 0);
                objUSER.USER_COMPANY_ID   = reader["USER_COMPANY_ID"] == DBNull.Value ? null : (int?)reader["USER_COMPANY_ID"];
                reader.Close();
                reader.Dispose();
            }
            return(objUSER);
        }
Exemple #2
0
        public USERDC AuthenticateUser(DBConnection Connection, string username, string password)
        {
            password = Encryptor.Encrypt(password);
            USERDC        objUSER = new USERDC();
            StringBuilder sql     = new StringBuilder();

            sql.Append("proc_USERSLoadByUserNamePassword");

            DBCommandWarpper dbCommandWrapper = new DBCommandWarpper(Connection.dataBase.GetStoredProcCommand(sql.ToString()), Connection);

            dbCommandWrapper.AddInParameter("p_USER_NAME", DbType.String, username);
            dbCommandWrapper.AddInParameter("p_PASSWORD", DbType.String, password);

            DataSet ds = new DataSet();

            if (Connection.Transaction != null)
            {
                ds = Connection.dataBase.ExecuteDataSet(dbCommandWrapper.DBCommand, Connection.Transaction);
            }
            else
            {
                ds = Connection.dataBase.ExecuteDataSet(dbCommandWrapper.DBCommand);
            }

            if (ds.Tables[0].Rows.Count > 0)
            {
                objUSER = (FillObject(ds.Tables[0].Rows[0]));
            }
            return(objUSER);
        }
Exemple #3
0
        public int UpdateUser(USERDC objUser)
        {
            int          updatedCount  = 0;
            DBConnection objConnection = new DBConnection();
            USERDA       objUSERDA     = new USERDA();

            try
            {
                objConnection.Open(true);
                updatedCount = objUSERDA.UpdateUser(objConnection, objUser);
                IsDirty      = objUSERDA.IsDirty;
                if (IsDirty)
                {
                    objConnection.Rollback();
                }
                else
                {
                    objConnection.Commit();
                }
            }
            catch (Exception ex)
            {
                objConnection.Rollback();
                throw ex;
            }
            finally
            {
                objConnection.Close();
            }
            return(updatedCount);
        }
Exemple #4
0
        public USERDC LoadByPrimaryKey(DBConnection Connection, int USER_ID)
        {
            USERDC        objUSER = new USERDC();
            StringBuilder sql     = new StringBuilder();

            sql.Append("proc_USERSLoadByPrimaryKey");

            DBCommandWarpper dbCommandWrapper = new DBCommandWarpper(Connection.dataBase.GetStoredProcCommand(sql.ToString()), Connection);

            dbCommandWrapper.AddInParameter("p_USER_ID", DbType.Int32, USER_ID);


            IDataReader reader = null;

            if (Connection.Transaction != null)
            {
                reader = Connection.dataBase.ExecuteReader(dbCommandWrapper.DBCommand, Connection.Transaction);
            }
            else
            {
                reader = Connection.dataBase.ExecuteReader(dbCommandWrapper.DBCommand);
            }

            objUSER = FillObject(reader);
            return(objUSER);
        }
Exemple #5
0
        public int Update(DBConnection Connection, USERDC objUSER)
        {
            int updateCount = 0;

            StringBuilder sql = new StringBuilder();

            sql.Append("proc_USERSUpdate");

            DBCommandWarpper dbCommandWrapper = new DBCommandWarpper(Connection.dataBase.GetStoredProcCommand(sql.ToString()), Connection);

            dbCommandWrapper.AddInParameter("p_USER_ID", DbType.Int32, objUSER.USER_ID);
            dbCommandWrapper.AddInParameter("p_USER_NAME", DbType.String, objUSER.USER_NAME);
            dbCommandWrapper.AddInParameter("p_PASSWORD", DbType.String, objUSER.PASSWORD);
            dbCommandWrapper.AddInParameter("p_FIRST_NAME", DbType.String, objUSER.FIRST_NAME);
            dbCommandWrapper.AddInParameter("p_LAST_NAME", DbType.String, objUSER.LAST_NAME);
            dbCommandWrapper.AddInParameter("p_ROLE_ID", DbType.Int32, objUSER.ROLE.ROLE_ID);
            dbCommandWrapper.AddInParameter("p_EMAIL_ADDRESS", DbType.String, objUSER.EMAIL_ADDRESS);
            dbCommandWrapper.AddInParameter("p_OFFICE_PHONE", DbType.String, objUSER.OFFICE_PHONE);
            dbCommandWrapper.AddInParameter("p_MOBILE_PHONE", DbType.String, objUSER.MOBILE_PHONE);
            dbCommandWrapper.AddInParameter("p_SECURITY_QUESTION", DbType.String, objUSER.SECURITY_QUESTION);
            dbCommandWrapper.AddInParameter("p_ANSWER", DbType.String, objUSER.ANSWER);
            dbCommandWrapper.AddInParameter("p_STATUS", DbType.String, objUSER.STATUS);
            dbCommandWrapper.AddInParameter("p_MODIFIED_BY", DbType.Int32, objUSER.MODIFIED_BY);
            dbCommandWrapper.AddInParameter("p_lock_counter", DbType.Int32, objUSER.LOCK_COUNTER);
            dbCommandWrapper.AddInParameter("p_USER_COMPANY_ID", DbType.Int32, objUSER.USER_COMPANY_ID);

            try
            {
                if (Connection.Transaction != null)
                {
                    updateCount = Connection.dataBase.ExecuteNonQuery(dbCommandWrapper.DBCommand, Connection.Transaction);
                }
                else
                {
                    updateCount = Connection.dataBase.ExecuteNonQuery(dbCommandWrapper.DBCommand);
                }

                if (updateCount == 0)
                {
                    objUSER.IsDirty = IsDirty = true;
                    throw new Exception(Constants.ConcurrencyMessageSingleRow);
                }
            }

            catch (Exception exp)
            {
                //Utilities.InsertIntoErrorLog("Error: USER UPDATE ", exp.Message + "\r\n" + exp.StackTrace, objUSER.MODIFIED_BY);
                objUSER.SetError(exp);
                throw exp;
            }

            return(updateCount);
        }
Exemple #6
0
        public IHttpActionResult Get(int id)
        {
            USERBL objUser   = new USERBL();
            USERDC objResult = new USERDC();

            try
            {
                objResult = objUser.LoadByPrimaryKey(id);
                return(Ok(new { objResult }));
            }
            catch (Exception ex)
            {
                return(new TextResult(ex.Message, Request, ex.StackTrace));
            }
        }
Exemple #7
0
        public int Insert(DBConnection Connection, USERDC objUSER)
        {
            int insertCount = 0;

            StringBuilder sql = new StringBuilder();

            sql.Append("proc_USERSInsert");

            DBCommandWarpper dbCommandWrapper = new DBCommandWarpper(Connection.dataBase.GetStoredProcCommand(sql.ToString()), Connection);


            dbCommandWrapper.AddOutParameter("p_USER_ID", DbType.Int32, Int32.MaxValue);
            dbCommandWrapper.AddInParameter("p_USER_NAME", DbType.String, objUSER.USER_NAME);
            dbCommandWrapper.AddInParameter("p_PASSWORD", DbType.String, Encryptor.Encrypt(objUSER.PASSWORD));
            dbCommandWrapper.AddInParameter("p_FIRST_NAME", DbType.String, objUSER.FIRST_NAME);
            dbCommandWrapper.AddInParameter("p_LAST_NAME", DbType.String, objUSER.LAST_NAME);
            dbCommandWrapper.AddInParameter("p_ROLE_ID", DbType.Int32, objUSER.ROLE.ROLE_ID);
            dbCommandWrapper.AddInParameter("p_EMAIL_ADDRESS", DbType.String, objUSER.EMAIL_ADDRESS);
            dbCommandWrapper.AddInParameter("p_OFFICE_PHONE", DbType.String, objUSER.OFFICE_PHONE);
            dbCommandWrapper.AddInParameter("p_MOBILE_PHONE", DbType.String, objUSER.MOBILE_PHONE);
            dbCommandWrapper.AddInParameter("p_SECURITY_QUESTION", DbType.String, objUSER.SECURITY_QUESTION);
            dbCommandWrapper.AddInParameter("p_ANSWER", DbType.String, objUSER.ANSWER);
            dbCommandWrapper.AddInParameter("p_STATUS", DbType.String, objUSER.STATUS);
            dbCommandWrapper.AddInParameter("p_CREATED_BY", DbType.Int32, objUSER.CREATED_BY);
            dbCommandWrapper.AddInParameter("p_USER_COMPANY_ID", DbType.Int32, objUSER.USER_COMPANY_ID);

            try
            {
                if (Connection.Transaction != null)
                {
                    insertCount = Connection.dataBase.ExecuteNonQuery(dbCommandWrapper.DBCommand, Connection.Transaction);
                }
                else
                {
                    insertCount = Connection.dataBase.ExecuteNonQuery(dbCommandWrapper.DBCommand);
                }
            }
            catch (Exception exp)
            {
                //Utilities.InsertIntoErrorLog("Error: USER INSERTION ", exp.Message + "\r\n" + exp.StackTrace, objUSER.MODIFIED_BY);
                objUSER.SetError(exp);
                throw exp;
            }

            objUSER.USER_ID = (int)dbCommandWrapper.DBCommand.Parameters["@p_USER_ID"].Value;

            return(insertCount);
        }
Exemple #8
0
        public IHttpActionResult AuthenticateUser(string username, string password)
        {
            USERBL objUser   = new USERBL();
            USERDC objResult = new USERDC();

            //try
            //{
            objResult = objUser.AuthenticateUser(username, password);
            CheckLoginAttempts(username, objResult);
            return(Ok(new { objResult }));
            //}
            //catch (Exception ex)
            //{
            //   return new TextResult(ex.Message, Request,ex.StackTrace);
            //}
        }
Exemple #9
0
        public IHttpActionResult UpdateUser([FromBody] USERDC objUser)
        {
            USERBL             objUserBL    = new USERBL();
            List <EXCEPTIONDC> lstException = new List <EXCEPTIONDC>();

            try
            {
                #region User Profile Checks
                if (!String.IsNullOrEmpty(objUser.NEW_PSWD))
                {
                    String errorMessage = String.Empty;
                    if (Encryptor.Encrypt(objUser.OLD_PSWD) != objUser.PASSWORD)
                    {
                        errorMessage += "Incorrect old password.</br>";
                    }
                    if (Encryptor.Encrypt(objUser.NEW_PSWD) == objUser.PASSWORD)
                    {
                        errorMessage += "New password should be different than the last password.</br>";
                    }
                    int minPswdLength = -1;
                    Int32.TryParse(ConfigurationManager.AppSettings["MinPasswordLength"], out minPswdLength);
                    if (minPswdLength != -1 && objUser.NEW_PSWD.Length < minPswdLength)
                    {
                        errorMessage += "Password should be minimun of " + minPswdLength + " chracters.</br>";
                    }
                    if (!String.IsNullOrEmpty(errorMessage))
                    {
                        return(new TextResult(errorMessage, Request, "User Profile Custom Error"));
                    }

                    objUser.PASSWORD = Encryptor.Encrypt(objUser.NEW_PSWD);
                }
                #endregion
                List <USERDC> objUsers = new List <USERDC>();
                objUsers.Add(objUser);
                int IsUpdated = objUserBL.Update(objUsers, ref lstException);
                return(Ok(new { IsUpdated }));
            }
            catch (Exception ex)
            {
                return(new TextResult(ex.Message, Request, ex.StackTrace));
            }
        }
Exemple #10
0
        private void CheckLoginAttempts(string username, USERDC objResult)
        {
            USERBL objUserHandler      = new USERBL();
            Int32  allowedLoginAttempt = ConfigurationManager.AppSettings.Get("FailedLoginAttempts") == "" ? 6 : Convert.ToInt32(ConfigurationManager.AppSettings.Get("FailedLoginAttempts"));
            Int32  currentLoginAttempt = 0;

            List <KeyValuePair <string, Int32> > users       = (List <KeyValuePair <string, Int32> >)System.Web.HttpContext.Current.Application["LoginAttempts"];
            KeyValuePair <string, Int32>         currentUser = users.Find(item => item.Key == username);

            if (currentUser.Key == null || currentUser.Key == "")
            {
                users.Add(new KeyValuePair <string, int>(username, currentLoginAttempt));
            }
            else
            {
                currentLoginAttempt = currentUser.Value;
            }

            if (objResult != null && objResult.USER_ID > 0)
            {
                currentLoginAttempt = 0;
            }
            else
            {
                currentLoginAttempt += 1;
            }

            objResult.ALLOWED_LOGIN_ATTEMPTS = allowedLoginAttempt;
            objResult.FAILED_LOGIN_ATTEMPTS  = currentLoginAttempt;
            if (currentLoginAttempt >= allowedLoginAttempt)
            {
                Int32 updatedRows = objUserHandler.UpdateUserLoginStatus(username, "N");
                if (updatedRows > 0)
                {
                    currentLoginAttempt = 0;
                    objResult.FAILED_LOGIN_ATTEMPT_MESSAGE = "Login credentials temporarily disabled due to " + objResult.ALLOWED_LOGIN_ATTEMPTS + " failed attempts. Contact your administrator for login.";
                }
            }

            users.Remove(users.Find(item => item.Key == username));
            users.Add(new KeyValuePair <string, int>(username, currentLoginAttempt));
        }
Exemple #11
0
        public USERDC AuthenticateUser(string username, string password)
        {
            DBConnection objConnection = new DBConnection();
            USERDA       objUSERDA     = new USERDA();
            USERDC       objUSERDC     = null;

            try
            {
                objConnection.Open(false);
                objUSERDC = objUSERDA.AuthenticateUser(objConnection, username, password);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objConnection.Close();
            }
            return(objUSERDC);
        }
Exemple #12
0
        public USERDC LoadByPrimaryKey(int USER_ID)
        {
            DBConnection objConnection = new DBConnection();
            USERDA       objUSERDA     = new USERDA();
            USERDC       objUSERDC     = null;

            try
            {
                objConnection.Open(false);
                objUSERDC = objUSERDA.LoadByPrimaryKey(objConnection, USER_ID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objConnection.Close();
            }
            return(objUSERDC);
        }
Exemple #13
0
        public int UpdateUserCompanies(DBConnection Connection, USERDC objUSER)
        {
            int updateCount = 0;

            StringBuilder sql = new StringBuilder();

            sql.Append("proc_USERSUpdateUSERS_COMPANIES");

            SqlDatabase database = (SqlDatabase)Connection.dataBase;

            DbCommand cmd = database.GetStoredProcCommand(sql.ToString());

            database.AddInParameter(cmd, "p_USER_ID", SqlDbType.Int, objUSER.USER_ID);
            database.AddInParameter(cmd, "@p_USERS_COMPANIES_IDs", SqlDbType.Structured, Utility.CreateIDsTable(objUSER.USER_COMPANIES));
            try
            {
                if (Connection.Transaction != null)
                {
                    updateCount = database.ExecuteNonQuery(cmd, Connection.Transaction);
                }
                else
                {
                    updateCount = database.ExecuteNonQuery(cmd);
                }

                if (updateCount == 0)
                {
                    objUSER.IsDirty = IsDirty = true;
                }
            }
            catch (Exception exp)
            {
                //Utilities.InsertIntoErrorLog("Error: USERS_COMPANIES UPDATE ", exp.Message + "\r\n" + exp.StackTrace, objUSER.MODIFIED_BY);
                objUSER.SetError(exp);
                throw exp;
            }

            return(updateCount);
        }
Exemple #14
0
        private int Delete(DBConnection Connection, USERDC objUSER)
        {
            int deleteCount = 0;

            StringBuilder sql = new StringBuilder();

            sql.Append("proc_USERSDelete");

            DBCommandWarpper dbCommandWrapper = new DBCommandWarpper(Connection.dataBase.GetStoredProcCommand(sql.ToString()), Connection);

            dbCommandWrapper.AddInParameter("p_USER_ID", DbType.Int32, objUSER.USER_ID);

            if (Connection.Transaction != null)
            {
                deleteCount = Connection.dataBase.ExecuteNonQuery(dbCommandWrapper.DBCommand, Connection.Transaction);
            }
            else
            {
                deleteCount = Connection.dataBase.ExecuteNonQuery(dbCommandWrapper.DBCommand);
            }

            return(deleteCount);
        }
Exemple #15
0
        public List <USERDC> LoggedUsers(DBConnection Connection)
        {
            List <USERDC> objUSER = new List <USERDC>();
            USERDC        ObjUserDC;
            StringBuilder sql = new StringBuilder();

            sql.Append("proc_LOGGEDUSERS");

            DBCommandWarpper dbCommandWrapper = new DBCommandWarpper(Connection.dataBase.GetStoredProcCommand(sql.ToString()), Connection);


            DataSet ds = new DataSet();

            if (Connection.Transaction != null)
            {
                ds = Connection.dataBase.ExecuteDataSet(dbCommandWrapper.DBCommand, Connection.Transaction);
            }
            else
            {
                ds = Connection.dataBase.ExecuteDataSet(dbCommandWrapper.DBCommand);
            }

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow drRow in ds.Tables[0].Rows)
                {
                    ObjUserDC               = new USERDC();
                    ObjUserDC.USER_NAME     = (String)drRow["USER_NAME"];
                    ObjUserDC.EMAIL_ADDRESS = (String)drRow["EMAIL_ADDRESS"];
                    ObjUserDC.ANSWER        = drRow["COMPANIES"] == DBNull.Value ? "" : (String)drRow["COMPANIES"];
                    ObjUserDC.LAST_LOGIN    = drRow["LAST_LOGIN"] == DBNull.Value ? DateTime.Now.ToString("dd-MM-yy HH:mm") : ((DateTime)drRow["LAST_LOGIN"]).ToString("dd-MM-yy HH:mm");
                    objUSER.Add(ObjUserDC);
                }
            }

            return(objUSER);
        }
Exemple #16
0
        public List <USERDC> GetUsersByUsername(string userName, DBConnection Connection)
        {
            List <USERDC> usersList = new List <USERDC>();

            StringBuilder sql = new StringBuilder();

            sql.Append("proc_USERSGetByUsername");

            DBCommandWarpper dbCommandWrapper = new DBCommandWarpper(Connection.dataBase.GetStoredProcCommand(sql.ToString()), Connection);

            dbCommandWrapper.AddInParameter("p_USERNAME", DbType.String, userName);

            DataSet ds = new DataSet();

            if (Connection.Transaction != null)
            {
                ds = Connection.dataBase.ExecuteDataSet(dbCommandWrapper.DBCommand, Connection.Transaction);
            }
            else
            {
                ds = Connection.dataBase.ExecuteDataSet(dbCommandWrapper.DBCommand);
            }

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                USERDC user = new USERDC();
                user.USER_ID           = Convert.ToInt32(row["USER_ID"]);
                user.USER_NAME         = Convert.ToString(row["USER_NAME"]);
                user.SECURITY_QUESTION = Convert.ToString(row["SECURITY_QUESTION"]);
                user.ANSWER            = Convert.ToString(row["ANSWER"]);
                user.EMAIL_ADDRESS     = Convert.ToString(row["EMAIL_ADDRESS"]);

                usersList.Add(user);
            }
            return(usersList);
        }
Exemple #17
0
 public int UpdateUser(DBConnection Connection, USERDC objUser)
 {
     return(Update(Connection, objUser));
 }
Exemple #18
0
        public int Update(List <USERDC> objUSERs, ref List <EXCEPTIONDC> lstExceptions)
        {
            int          updatedCount  = 0;
            DBConnection objConnection = new DBConnection();
            USERDA       objUSERDA     = new USERDA();

            try
            {
                foreach (USERDC objUSER in objUSERs)
                {
                    objConnection.Open(true);
                    try
                    {
                        objUSER.MODIFIED_ON = DateTime.Now;
                        updatedCount        = objUSERDA.Update(objConnection, objUSER);
                        if (objUSERDA.IsDirty)
                        {
                            break;
                        }

                        ///  Email sent an Match Complete
                        int           EmailSent     = 0;
                        MESSAGEDC     objMsgDC      = new MESSAGEDC();
                        MESSAGEBL     objMsgBL      = new MESSAGEBL();
                        List <string> lstUserEmails = new List <string>();
                        USERDA        objUser       = new USERDA();
                        USERDC        objUserDC     = new USERDC();

                        objUserDC = objUser.LoadByPrimaryKey(objConnection, objUSER.USER_ID);

                        // lstUserEmails = objUser.GetUsersEmailAddressByEventId(objUSER.USER_ID, "", 62, objConnection);

                        //if (lstUserEmails.Count > 0)
                        //{
                        Task.Run(() =>
                        {
                            //if (!lstUserEmails.Contains(objUSER.EMAIL_ADDRESS))
                            //    lstUserEmails.Add(objUSER.EMAIL_ADDRESS);
                            StringBuilder strContents = new StringBuilder();
                            strContents.Append("<!DOCTYPE HTML><html><body><table>");
                            strContents.Append("<tr><td>Profile for user  <b>" + objUSER.USER_NAME + "</b>. has been updated.");
                            strContents.Append("<tr><td>Please log into the system to verify changes.");
                            strContents.Append("</table></body></html>");
                            try
                            {
                                objMsgDC.FROM       = GetSMTPAdminEmail();
                                objMsgDC.SUBJECT    = "Your profile is changed.";
                                objMsgDC.CONTENTS   = strContents.ToString();
                                objMsgDC.RECIPIENTS = String.Join(";", objUserDC.EMAIL_ADDRESS);
                                EmailSent           = objMsgBL.SendSMTPEmail(objMsgDC, true);
                            }
                            catch (Exception exp)
                            {
                                EPay.DataAccess.Utilities.InsertIntoErrorLog("Error: USER PROFILE CHANGED NOTIFICATION EMAIL ", exp.Message + "\r\n" + exp.StackTrace, objUSER.MODIFIED_BY);
                            }
                        });
                        // }
                        objConnection.Commit();
                    }
                    catch (Exception exp)
                    {
                        EXCEPTIONDC objExcption = new EXCEPTIONDC();
                        objExcption.FIELD_ID          = objUSER.USER_ID;
                        objExcption.EXCEPTION_MESSAGE = exp.Message;
                        objExcption.STACK_TRACK       = exp.StackTrace;
                        lstExceptions.Add(objExcption);
                        objConnection.Rollback();
                        // throw exp;
                    }
                }
                if (lstExceptions.Count > 0)
                {
                    throw new Exception(lstExceptions[0].EXCEPTION_MESSAGE);
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
            finally
            {
                objConnection.Close();
            }

            return(updatedCount);
        }
Exemple #19
0
        public int Insert(List <USERDC> objUSERs)
        {
            int          insertedCount = 0;
            bool         IsDirty       = false;
            DBConnection objConnection = new DBConnection();
            USERDA       objUSERDA     = new USERDA();

            try
            {
                objConnection.Open(true);
                foreach (USERDC objUSER in objUSERs)
                {
                    objUSER.CREATED_ON = objUSER.MODIFIED_ON = DateTime.Now;
                    objUSER.PASSWORD   = Utility.GenerateRandomPassword(8);
                    insertedCount      = objUSERDA.Insert(objConnection, objUSER);
                    if (objUSER.USER_ID == -111)
                    {
                        throw new Exception("User Name '" + objUSER.USER_NAME + "' already exists. All other changes saved successfully.");
                    }

                    //IsDirty = objUSERDA.IsDirty;
                    //if (IsDirty == false)
                    //{
                    //    objUSERDA.UpdateUserCompanies(objConnection, objUSER);
                    //}
                    //else
                    //{
                    //    break;
                    //}

                    int       EmailSent = 0;
                    MESSAGEDC objMsgDC  = new MESSAGEDC();
                    MESSAGEBL objMsgBL  = new MESSAGEBL();
                    USERDA    objUser   = new USERDA();
                    USERDC    objUserDC = new USERDC();

                    objUserDC = objUser.LoadByPrimaryKey(objConnection, objUSER.USER_ID);
                    Task.Run(() =>
                    {
                        StringBuilder strContents = new StringBuilder();
                        strContents.Append("<!DOCTYPE HTML><html><body><table>");
                        strContents.Append("<tr><td>Your profile for Hylan has been created.</td></tr><tr><td></td></tr>");
                        strContents.Append("<tr><td>Following are your account credentials:</td></tr><tr><td></td></tr>");
                        strContents.Append("<tr><td><b>Username:</b> " + objUSER.USER_NAME + "</td></tr>");
                        strContents.Append("<tr><td><b>Password:</b> " + objUSER.PASSWORD + "</td></tr>");
                        strContents.Append("</table></body></html>");
                        try
                        {
                            objMsgDC.FROM       = objUserDC.EMAIL_ADDRESS;
                            objMsgDC.SUBJECT    = "Your profile is created.";
                            objMsgDC.CONTENTS   = strContents.ToString();
                            objMsgDC.RECIPIENTS = objUSER.EMAIL_ADDRESS;
                            EmailSent           = objMsgBL.SendSMTPEmail(objMsgDC, true);
                        }
                        catch (Exception exp)
                        {
                            EPay.DataAccess.Utilities.InsertIntoErrorLog("Error: USER PROFILE CREATED NOTIFICATION EMAIL ", exp.Message + "\r\n" + exp.StackTrace, objUSER.MODIFIED_BY);
                        }
                    });
                }
                if (IsDirty)
                {
                    objConnection.Rollback();
                }
                else
                {
                    objConnection.Commit();
                }
            }
            catch (Exception ex)
            {
                objConnection.Rollback();
                throw ex;
            }
            finally
            {
                objConnection.Close();
            }
            return(insertedCount);
        }
Exemple #20
0
        private USERDC FillObject(DataRow row)
        {
            USERDC objUSER = null;

            objUSER           = new USERDC();
            objUSER.USER_ID   = (int)row["USER_ID"];
            objUSER.USER_NAME = (String)row["USER_NAME"];
            if (row.Table.Columns.Contains("PASSWORD"))
            {
                objUSER.PASSWORD = (String)row["PASSWORD"];
            }
            objUSER.FIRST_NAME = (String)row["FIRST_NAME"];
            objUSER.LAST_NAME  = (String)row["LAST_NAME"];
            if (row.Table.Columns.Contains("ROLE_ID"))
            {
                objUSER.ROLE.ROLE_ID = (int)row["ROLE_ID"];
            }
            if (row.Table.Columns.Contains("IS_RESTRICTED"))
            {
                objUSER.ROLE.IS_RESTRICTED = (row["IS_RESTRICTED"] == DBNull.Value) ? false : Convert.ToBoolean(row["IS_RESTRICTED"]);
            }
            objUSER.ROLE.ROLE_NAME = (String)row["ROLE_NAME"];
            if (row.Table.Columns.Contains("COMPANIES"))
            {
                objUSER.USER_COMPANIES = row["COMPANIES"] == DBNull.Value ? new int[] { } : Array.ConvertAll <string, int>(((String)row["COMPANIES"]).Split(','), Convert.ToInt32);
            }
            if (row.Table.Columns.Contains("COMPANIES_NAMES"))
            {
                objUSER.USER_COMPANIES_NAMES = (row["COMPANIES_NAMES"] == DBNull.Value) ? "" : Convert.ToString(row["COMPANIES_NAMES"]);
            }
            objUSER.EMAIL_ADDRESS = (String)row["EMAIL_ADDRESS"];
            objUSER.OFFICE_PHONE  = row["OFFICE_PHONE"] == DBNull.Value ? null : (String)row["OFFICE_PHONE"];
            objUSER.MOBILE_PHONE  = row["MOBILE_PHONE"] == DBNull.Value ? null : (String)row["MOBILE_PHONE"];
            if (row.Table.Columns.Contains("SECURITY_QUESTION"))
            {
                objUSER.SECURITY_QUESTION = row["SECURITY_QUESTION"] == DBNull.Value ? null : (String)row["SECURITY_QUESTION"];
            }
            if (row.Table.Columns.Contains("ANSWER"))
            {
                objUSER.ANSWER = row["ANSWER"] == DBNull.Value ? null : (String)row["ANSWER"];
            }
            objUSER.STATUS = (String)row["STATUS"];
            if (row.Table.Columns.Contains("CREATED_ON"))
            {
                objUSER.CREATED_ON = (DateTime)row["CREATED_ON"];
            }
            if (row.Table.Columns.Contains("CREATED_BY"))
            {
                objUSER.CREATED_BY = (int)row["CREATED_BY"];
            }
            if (row.Table.Columns.Contains("MODIFIED_ON"))
            {
                objUSER.MODIFIED_ON = (DateTime)row["MODIFIED_ON"];
            }
            if (row.Table.Columns.Contains("MODIFIED_BY"))
            {
                objUSER.MODIFIED_BY = (int)row["MODIFIED_BY"];
            }
            if (row.Table.Columns.Contains("LOCK_COUNTER"))
            {
                objUSER.LOCK_COUNTER = (!string.IsNullOrEmpty(row["LOCK_COUNTER"].ToString()) ? (int)row["LOCK_COUNTER"] : 0);
            }
            if (row.Table.Columns.Contains("SCREENS"))
            {
                objUSER.USER_SCREENS = row["SCREENS"] == DBNull.Value ? new int[] { } : Array.ConvertAll <string, int>(((String)row["SCREENS"]).Split(','), Convert.ToInt32);
            }
            if (row.Table.Columns.Contains("PASSWORD_MODIFIED_ON"))
            {
                objUSER.PASSWORD_MODIFIED_ON = (DateTime)row["PASSWORD_MODIFIED_ON"];
            }
            if (row.Table.Columns.Contains("PASSWORD_AGE"))
            {
                objUSER.PASSWORD_AGE = Convert.ToDouble(row["PASSWORD_AGE"]);
            }
            if (row.Table.Columns.Contains("HOME_RMAGS"))
            {
                objUSER.HOME_RMAGS = row["HOME_RMAGS"] == DBNull.Value ? new int[] { } : Array.ConvertAll <string, int>(((String)row["HOME_RMAGS"]).Split(','), Convert.ToInt32);
            }
            if (row.Table.Columns.Contains("USER_COMPANY_ID"))
            {
                objUSER.USER_COMPANY_ID = row["USER_COMPANY_ID"] == DBNull.Value ? null : (int?)row["USER_COMPANY_ID"];
            }
            return(objUSER);
        }