public EmployeeDATA GetUserInfo(string userid) { EmployeeDATA employeeDATA = null; SqlCommand command = new SqlCommand(); SqlDataReader dataReader = null; #region Connection Database SqlConnection connection = new SqlConnection(); connection = this.ManageConnection(); command.Connection = connection; #endregion #region Send Query command.CommandType = CommandType.Text; command.CommandText = "select * from TBLUSERPROFILE where USERID = '" + userid + "' "; #endregion #region Return Data dataReader = command.ExecuteReader(); if (dataReader != null && dataReader.HasRows) { employeeDATA = new EmployeeDATA(); while (dataReader.Read()) { employeeDATA.USERID = dataReader["USERID"].ToString(); employeeDATA.FIRSTNAME = dataReader["FIRSTNAME"].ToString(); employeeDATA.LASTNAME = dataReader["LASTNAME"].ToString(); employeeDATA.DEPARTMENT = dataReader["DEPARTMENT"].ToString(); employeeDATA.MOBILE = dataReader["MOBILE"].ToString(); employeeDATA.POSITION = dataReader["POSITION"].ToString(); } } #endregion return(employeeDATA); }
// GET: WF public ActionResult Index() { EmployeeDATA employeeDATA = new EmployeeDATA(); RequestDATA requestDATA = new RequestDATA(); if (Session["userid"] != null) { string userid = Session["userid"].ToString(); EmployeeDAL employeeDAL = new EmployeeDAL(); employeeDATA = employeeDAL.GetUserInfo(userid); if (employeeDATA != null) { RequestDAL requestDAL = new RequestDAL(); List <RequestDATA> listData = requestDAL.GetRequestByUserId(userid); requestDATA.LSTREQ = listData; //แปลงเป็น JSON string json = JsonConvert.SerializeObject(requestDATA); requestDATA.JSON = json; //แปลงเป็น OBJECT requestDATA = JsonConvert.DeserializeObject <RequestDATA>(json); if (requestDATA.LSTREQ.Count > 0) { ViewData["REQDATA"] = requestDATA.LSTREQ; } } } return(View(employeeDATA)); }