示例#1
0
        public void SaveRoles(RolesModel roles)
        {
            string SqlQuetion = "SaveRoles";

            using (var connection = new SqlConnection(connectionLine))
            {
                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                }

                using (var command = new SqlCommand(SqlQuetion, connection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    var paramRole        = new SqlParameter("@Role", roles.Role);
                    var paramDescription = new SqlParameter("@Description", roles.Description);

                    command.Parameters.Add(paramRole);
                    command.Parameters.Add(paramDescription);

                    command.ExecuteNonQuery();
                }
            }
        }
示例#2
0
        public List <RolesModel> GetRoles()
        {
            string SqlQuetion = "GetRoles";
            var    listRoles  = new List <RolesModel>();

            using (var connection = new SqlConnection(connectionLine))
            {
                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                }

                using (var command = new SqlCommand(SqlQuetion, connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var roles = new RolesModel();
                            roles.Id          = reader.GetInt32(0);
                            roles.Role        = reader.GetString(1);
                            roles.Description = reader.GetString(2);
                            listRoles.Add(roles);
                        }
                    }
                }
            }
            return(listRoles);
        }