Exemple #1
0
        public string ValidateUser(string userName, string passWord)
        {
            string returnString = IdProConstants.SUCCESS;
            userName = userName.ToUpper().Trim();
            passWord = passWord.Trim();

            UserDAO userDao = new UserDAO();

            User user = userDao.getUserByUserName(userName);
            string hash = getHashPassword(passWord);
            if (user == null)
            {
                returnString = "User Can not be found in the system";

            }
            else if (!user.Password.Trim().Equals(getHashPassword(passWord)))
            {
                returnString = "Invalid Password";
            }

            return returnString;
        }
Exemple #2
0
        public bool isUserNameExist(string userName)
        {
            UserDAO userDao = new UserDAO();

            return userDao.getUserByUserName(userName.Trim().ToUpper()) != null;
        }
Exemple #3
0
 public User getUserbyUserName(string userName)
 {
     UserDAO userDao = new UserDAO();
     return userDao.getUserByUserName(userName);
 }
        public string updateEmployee(Employee employee)
        {
            SqlConnection conn = null;
            SqlTransaction trans = null;
            string returnString = IdProConstants.SUCCESS;
            UserDAO userDao = new UserDAO();
            EmployeeDao EmployeeDao = new EmployeeDao();
            ConnectionDao ConnectionDao = new ConnectionDao();
            UserServices userServices = new UserServices();
            Employee employeeById = EmployeeDao.getEmployeeById(employee.EmployeeId);
            if (!(employeeById.Email.Trim().Equals(employee.Email.Trim())) && isEmployeeEmailexist(employee.Email.Trim()))
            {
                returnString = "Employee Email already Exist in the system";
            }
            else if (!(employeeById.USER.Username.Trim().ToUpper().Equals(employee.USER.Username.Trim().ToUpper())) && userServices.isUserNameExist(employee.USER.Username))
            {
                returnString = "UserName already Exit in the system";
            }
            else
            {
                try
                {
                    conn = ConnectionDao.getConnection();
                    trans = conn.BeginTransaction();
                    HttpContext.Current.Session["prevUserName"] = employeeById.USER.Username;
                    returnString = userDao.updateUser(conn, trans, employee.USER);
                    if (IdProConstants.SUCCESS.Equals(returnString))
                    {
                        returnString = EmployeeDao.updateEmployee(conn, trans, employee);
                    }
                    if (IdProConstants.SUCCESS.Equals(returnString))
                    {
                        trans.Commit();
                    }
                    else
                    {
                        trans.Rollback();
                    }
                }
                catch (Exception exception)
                {
                    trans.Rollback();
                    System.Diagnostics.Trace.WriteLine("[EmployeeServices:updateEmployee] Exception " + exception.StackTrace);

                }
                finally
                {
                    ConnectionDao.closeConnection(conn);

                }
            }

            return returnString;
        }
        public string addEmployee(Employee employee)
        {
            SqlConnection conn = null;
            SqlTransaction trans = null;

            string returnString = IdProConstants.SUCCESS;

            UserDAO userDao = new UserDAO();
            EmployeeDao EmployeeDao = new EmployeeDao();
            ConnectionDao ConnectionDao = new ConnectionDao();
            UserServices userServices = new UserServices();

            if (isEmployeeEmailexist(employee.Email.Trim()))
            {
                returnString = "Employee Email already Exist in the system";
            }
            // else if (userServices.isUserNameExist(employee.USER.Username))
            else if (userServices.isUserNameExist(employee.Username))
            {
                returnString = "UserName already Exit in the system";
            }
            else
            {

                try
                {
                    conn = ConnectionDao.getConnection();

                    trans = conn.BeginTransaction();

                    returnString = userDao.addUser(conn, trans, employee.USER);

                    if (IdProConstants.SUCCESS.Equals(returnString))
                    {
                        returnString = EmployeeDao.addEmployee(conn, trans, employee);

                    }

                    if (IdProConstants.SUCCESS.Equals(returnString))
                    {
                        trans.Commit();

                    }
                    else
                    {
                        trans.Rollback();
                    }
                }
                catch (Exception exception)
                {
                    trans.Rollback();
                    System.Diagnostics.Trace.WriteLine("[EmployeeServices:addEmployee] Exception " + exception.StackTrace);

                }
                finally
                {
                    ConnectionDao.closeConnection(conn);

                }
            }

            return returnString;
        }
Exemple #6
0
        public Employee getEmployeeByUserName(string userName)
        {
            ConnectionDao ConnectionDao = new ConnectionDao();
            Employee employee = new Employee();

            SqlCommand cmd = null;
            SqlConnection conn = null;
            SqlDataReader rs = null;

            string query = "select * from employees where userName=@userName";

            try
            {
                conn = ConnectionDao.getConnection();
                cmd = ConnectionDao.getSqlCommandWithoutTransaction(query, conn);

                SqlParameter param1 = new SqlParameter();
                param1.ParameterName = "@userName";
                param1.Value = userName;
                cmd.Parameters.Add(param1);

                rs = cmd.ExecuteReader();

                if (rs.Read())
                {
                    employee.FirstName=(rs["first_name"].ToString().Trim());
                    employee.LastName=(rs["last_name"].ToString().Trim());
                    employee.Email=(rs["email"].ToString().Trim());
                    employee.EmployeeStatus=(rs["status"].ToString().Trim());
                    employee.EmployeeId = (rs["Employee_Id"].ToString().Trim());
                    employee.department  = (rs["department"].ToString().Trim());
                    UserDAO userDao = new UserDAO();

                    User user = userDao.getUserByUserName(userName);
                    employee.USER=user;

                }
                else
                {
                    employee = null;
                }

            }
            catch (Exception exception)
            {
                System.Diagnostics.Trace.WriteLine("[EmployeeDAO:getEmployeeByUserName] Exception " + exception.StackTrace);
                employee = null;

            }
            finally
            {
                ConnectionDao.closeConnection(conn);
                ConnectionDao.closeDabaseEntities(cmd, rs);
            }

            return employee;
        }