Exemple #1
0
        /// <summary>
        /// Check login status based on username and password provided
        /// </summary>
        /// <param name="username">user login name</param>
        /// <param name="password">user password</param>
        /// <returns>return values defined in Constants.LoginResult. </returns>
        public static VaaaN.MLFF.Libraries.CommonLibrary.Constants.LoginResult ValidateUser(string loginName, string password, ref VaaaN.MLFF.Libraries.CommonLibrary.CBE.UserCBE currentUser)
        {
            VaaaN.MLFF.Libraries.CommonLibrary.Constants.LoginResult result = VaaaN.MLFF.Libraries.CommonLibrary.Constants.LoginResult.InvalidUser;
            CBE.UserCollection users = new CBE.UserCollection();

            try
            {
                users = VaaaN.MLFF.Libraries.CommonLibrary.DAL.LoginDAL.GetUserByLoginName(loginName);

                if (users.Count == 0)
                {
                    result = VaaaN.MLFF.Libraries.CommonLibrary.Constants.LoginResult.InvalidUser;
                }
                else
                {
                    foreach (CBE.UserCBE user in users)
                    {
                        if (user.LoginName.ToLower() == loginName.ToLower() && user.Password == VaaaN.MLFF.Libraries.CommonLibrary.Cryptography.Encryption.ComputeHash(password))
                        {
                            result      = VaaaN.MLFF.Libraries.CommonLibrary.Constants.LoginResult.Successful;
                            currentUser = user;

                            //Check Account expiry
                            if (currentUser.AccountExpiryDate < System.DateTime.Now)
                            {
                                result = VaaaN.MLFF.Libraries.CommonLibrary.Constants.LoginResult.AccountExpired;
                            }


                            break;
                        }
                        else
                        {
                            result = VaaaN.MLFF.Libraries.CommonLibrary.Constants.LoginResult.InvalidUser;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                result = VaaaN.MLFF.Libraries.CommonLibrary.Constants.LoginResult.DatabaseError;
                VaaaN.MLFF.Libraries.CommonLibrary.Logger.Log.Write("Failed to validate user. " + ex.ToString(), VaaaN.MLFF.Libraries.CommonLibrary.Logger.Log.ErrorLogModule.LoginModule);

                throw ex;
            }
            return(result);
        }
Exemple #2
0
 public static CBE.UserCollection GetUserAll()
 {
     CBE.UserCollection users = new CBE.UserCollection();
     try
     {
         //Stored procedure must have cur_out parameter.
         //There is no need to add ref cursor for oracle in code.
         string    spName  = Constants.oraclePackagePrefix + "User_GetAll";
         DbCommand command = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.GetStoredProcCommand(spName);
         users = ConvertDataTableToCollection(VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.LoadDataSet(command, tableName).Tables[tableName]);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(users);
 }
Exemple #3
0
        /// <summary>
        /// Get next value for the primary key
        /// </summary>
        /// <returns></returns>
        private static int GetNextValue()
        {
            //next value will be 1 if there is no row in the datatable.
            int nextValue = 1;

            try
            {
                //Get object collection
                CBE.UserCollection objs = GetUserAll();

                //Get all objects Id
                int[] sortedObjsId = new int[objs.Count];
                for (int i = 0; i < objs.Count; i++)
                {
                    sortedObjsId[i] = objs[i].UserId;
                }

                //Sort the object id
                Array.Sort(sortedObjsId);

                for (int j = 0; j < sortedObjsId.Length; j++)
                {
                    if (j + 1 < sortedObjsId.Length)
                    {
                        if (sortedObjsId[j] + 1 < sortedObjsId[j + 1])
                        {
                            nextValue = sortedObjsId[j] + 1;
                            break;
                        }
                    }
                    else
                    {
                        nextValue = sortedObjsId[sortedObjsId.Length - 1] + 1;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(nextValue);
        }
Exemple #4
0
        public static CBE.UserCBE GetUserById(CBE.UserCBE user)
        {
            try
            {
                CBE.UserCollection users = new CBE.UserCollection();

                string    spName  = Constants.oraclePackagePrefix + "User_GetById";
                DbCommand command = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.GetStoredProcCommand(spName);

                command.Parameters.Add(VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.CreateDbParameter(ref command, "p_user_id", DbType.Int32, user.UserId, ParameterDirection.Input));

                users = ConvertDataTableToCollection(VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.LoadDataSet(command, tableName).Tables[tableName]);

                return(users[0]);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #5
0
        public static CBE.UserCollection PagedGetAll(int startRowIndex, int endRowIndex, ref int totalRows)
        {
            CBE.UserCollection users = new CBE.UserCollection();
            try
            {
                //Stored procedure must have cur_out parameter.
                //There is no need to add ref cursor for oracle in code.
                string    spName  = Constants.oraclePackagePrefix + "User_PagedGetAll";
                DbCommand command = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.GetStoredProcCommand(spName);

                command.Parameters.Add(VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.CreateDbParameter(ref command, "p_start_row_index", DbType.Int32, startRowIndex, ParameterDirection.Input));
                command.Parameters.Add(VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.CreateDbParameter(ref command, "p_end_row_index", DbType.Int32, endRowIndex, ParameterDirection.Input));
                command.Parameters.Add(VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.CreateDbParameter(ref command, "p_total_rows", DbType.Int32, startRowIndex, ParameterDirection.Output));

                DataSet ds = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.LoadDataSet(command, tableName);
                totalRows = (int)command.Parameters["p_total_rows"].Value;
                users     = ConvertDataTableToCollection(ds.Tables[tableName]);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(users);
        }
Exemple #6
0
        private static CBE.UserCollection ConvertDataTableToCollection(DataTable dt)
        {
            try
            {
                CBE.UserCollection users = new CBE.UserCollection();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    CBE.UserCBE user = new CBE.UserCBE();

                    if (dt.Rows[i]["USER_ID"] != DBNull.Value)
                    {
                        user.UserId = Convert.ToInt32(dt.Rows[i]["USER_ID"]);
                    }
                    if (dt.Rows[i]["LOGIN_NAME"] != DBNull.Value)
                    {
                        user.LoginName = Convert.ToString(dt.Rows[i]["LOGIN_NAME"]);
                    }

                    if (dt.Rows[i]["FIRST_NAME"] != DBNull.Value)
                    {
                        user.FirstName = Convert.ToString(dt.Rows[i]["FIRST_NAME"]);
                    }

                    if (dt.Rows[i]["LAST_NAME"] != DBNull.Value)
                    {
                        user.LastName = Convert.ToString(dt.Rows[i]["LAST_NAME"]);
                    }

                    user.FullName = Convert.ToString(dt.Rows[i]["FIRST_NAME"]) + " " + Convert.ToString(dt.Rows[i]["LAST_NAME"]);

                    if (dt.Rows[i]["DESCRIPTION"] != DBNull.Value)
                    {
                        user.Description = Convert.ToString(dt.Rows[i]["DESCRIPTION"]);
                    }

                    if (dt.Rows[i]["PASSWORD"] != DBNull.Value)
                    {
                        user.Password = Convert.ToString(dt.Rows[i]["PASSWORD"]);
                    }

                    if (dt.Rows[i]["ADDRESS"] != DBNull.Value)
                    {
                        user.Address = Convert.ToString(dt.Rows[i]["ADDRESS"]);
                    }

                    if (dt.Rows[i]["ROLE_ID"] != DBNull.Value)
                    {
                        user.RoleId = Convert.ToInt32(dt.Rows[i]["ROLE_ID"]);
                    }

                    if (user.RoleId > 0)
                    {
                        foreach (VaaaN.MLFF.Libraries.CommonLibrary.CBE.RoleCBE role in VaaaN.MLFF.Libraries.CommonLibrary.BLL.RoleBLL.GetAll())
                        {
                            if (user.RoleId == role.RoleId)
                            {
                                user.RoleName = role.RoleName;
                                break;
                            }
                        }
                    }

                    if (dt.Rows[i]["ACC_EXPIRY_DATE"] != DBNull.Value)
                    {
                        user.AccountExpiryDate = Convert.ToDateTime(dt.Rows[i]["ACC_EXPIRY_DATE"]);
                    }

                    if (dt.Rows[i]["MODIFIER_ID"] != DBNull.Value)
                    {
                        user.ModifierId = Convert.ToInt32(dt.Rows[i]["MODIFIER_ID"]);
                    }

                    if (dt.Rows[i]["CREATION_DATE"] != DBNull.Value)
                    {
                        user.CreationDate = Convert.ToDateTime(dt.Rows[i]["CREATION_DATE"]);
                    }

                    if (dt.Rows[i]["MODIFICATION_DATE"] != DBNull.Value)
                    {
                        user.ModificationDate = Convert.ToDateTime(dt.Rows[i]["MODIFICATION_DATE"]);
                    }
                    if (dt.Rows[i]["USER_STATUS"] != DBNull.Value)
                    {
                        user.UserStatus = Convert.ToBoolean(dt.Rows[i]["USER_STATUS"]);
                    }
                    if (dt.Rows[i]["EMAIL_ID"] != DBNull.Value)
                    {
                        user.EmailId = Convert.ToString(dt.Rows[i]["EMAIL_ID"]);
                    }
                    if (dt.Rows[i]["MOBILE_NO"] != DBNull.Value)
                    {
                        user.MobileNo = Convert.ToString(dt.Rows[i]["MOBILE_NO"]);
                    }
                    if (dt.Rows[i]["MOBILE_NO"] != DBNull.Value)
                    {
                        user.MobileNo = Convert.ToString(dt.Rows[i]["MOBILE_NO"]);
                    }
                    if (dt.Rows[i]["DOB"] != DBNull.Value)
                    {
                        user.UserDob = Convert.ToDateTime(dt.Rows[i]["DOB"]);
                    }
                    users.Add(user);
                }
                return(users);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }