Exemple #1
0
        public ReturnRole DeleteByID(int _ID)
        {
            ReturnRole returnRole = new ReturnRole();

            try
            {
                // Gọi vào DB để lấy dữ liệu.
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        cmd.CommandText = "sp_tRole_DeleteByID";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = _ID;
                        cmd.ExecuteNonQuery();
                        returnRole.Code    = "00";
                        returnRole.Message = "Cập nhật dữ liệu thành công.";
                    }
                }
            }
            catch (Exception ex)
            {
                returnRole.Code    = "99";
                returnRole.Message = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnRole.Total   = 0;
                returnRole.lstRole = null;
                mylog4net.Error("", ex);
            }
            return(returnRole);
        }
Exemple #2
0
        public ReturnRole Insert(Role role)
        {
            ReturnRole returnRole = new ReturnRole();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        cmd.CommandText = "sp_tRole_InsertUpdate";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value            = role.ID;
                        cmd.Parameters.Add(new SqlParameter("@RoleName", SqlDbType.NVarChar)).Value = role.RoleName;
                        cmd.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar)).Value    = role.Title;
                        cmd.ExecuteNonQuery();

                        returnRole.Code    = "00";
                        returnRole.Message = "Cập nhật dữ liệu thành công.";
                    }
                }
            }
            catch (Exception ex)
            {
                returnRole.Code    = "99";
                returnRole.Message = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnRole.Total   = 0;
                returnRole.lstRole = null;
            }
            return(returnRole);
        }
Exemple #3
0
        public ReturnRole ListByUserID(int userID)
        {
            List <Role> lstRole    = null;
            Role        role       = null;
            ReturnRole  returnRole = new ReturnRole();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        cmd.CommandText = "[sp_tRole_SelectByUserID]";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@UserID", SqlDbType.Int)).Value = userID;

                        using (SqlDataReader sqlDr = ConnectSQLCommon.ExecuteDataReader(cmd))
                        {
                            //if (float.Parse(cmd.Parameters["P_RETURN_CODE"].Value.ToString()) > 0)
                            //{
                            if (sqlDr.HasRows)
                            {
                                lstRole = new List <Role>();
                                while (sqlDr.Read())
                                {
                                    role          = new Role();
                                    role.ID       = int.Parse(sqlDr["ID"].ToString());
                                    role.RoleName = sqlDr["RoleName"].ToString();
                                    role.Title    = sqlDr["Title"].ToString();

                                    lstRole.Add(role);
                                }
                                returnRole.Code    = "00";
                                returnRole.Message = "Lấy dữ liệu thành công.";
                                returnRole.lstRole = lstRole;
                            }
                            else
                            {
                                returnRole.Code    = "01";
                                returnRole.Message = "Không tồn tại bản ghi nào.";
                                returnRole.Total   = 0;
                                returnRole.lstRole = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                returnRole.Code    = "99";
                returnRole.Message = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnRole.Total   = 0;
                returnRole.lstRole = null;
                mylog4net.Error("", ex);
            }
            return(returnRole);
        }